gotool

package module
v0.0.0-...-5f11d87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

README

gotool

golang 的一些函数封装,方便自己使用 ####GoDoc

Documentation

Index

Constants

View Source
const (
	Byte = 1.0
	KB   = 1024 * Byte
	MB   = 1024 * KB
	GB   = 1024 * MB
	TB   = 1024 * GB
)

Variables

View Source
var (
	PrivateIPNet = []string{
		"10.0.0.0/8",
		"172.16.0.0/12",
		"192.168.0.0/16",
	}
)

Well-known IPv4 Private addresses

Functions

func ByteFormat

func ByteFormat(bytes uint64) string

将字节转成可读性好的格式 如 1024 转成 1.00 K

func CIDRToIPMask

func CIDRToIPMask(cidr string) (string, string, error)

将 1.1.1.0/24 转成1.1.1.0 255.255.255.0

func CIDRToIPRange

func CIDRToIPRange(cidr string) (startip string, endip string, err error)

将CIDR转成起始IP-结束IP,如 192.168.0.0/24 转成 192.168.0.0 192.168.0.255

func CIDRToUint32

func CIDRToUint32(cidr string) (start uint32, end uint32, err error)

将CIDR转成数字,如 1.0.0.0/24 转成 16777216 16777471

func Comma

func Comma(v int64) string

将数字转成逗号分隔形式便于阅读,如 1000 转成 1,000

func CreatePidFile

func CreatePidFile(path string) error

func Dial

func Dial(network string, local string, remote string) (net.Conn, error)

指定本机某IP 与remote IP连接

func FileLine

func FileLine() (string, int)

func GBKtoUTF8

func GBKtoUTF8(gbk string) string

func GetLocalIP

func GetLocalIP() ([]string, error)

获取本机网卡IP

func GetTag

func GetTag(o interface{}, FieldName, Tagkey string) (string, bool)

GetTag 获取结构体o的FieldName的Tag值

func IPMaskToCIDR

func IPMaskToCIDR(ip string, mask string) string

将 1.1.1.0 255.255.255.0 转成 1.1.1.0/24

func IPNetMaskBit

func IPNetMaskBit(startip string, endip string) (bit int, err error)

用startip,endip计算子网掩码长度,如192.168.0.0 192.168.0.255 返回 24

func IPRangeToCIDR

func IPRangeToCIDR(startip string, endip string) (cidr string, err error)

将起始IP-结束IP转成CIDR,如 192.168.0.0 192.168.0.255 转成 192.168.0.0/24

func IPv4toUint32

func IPv4toUint32(ip string) (uint32, error)

ip格式转uint32

func InverseMask

func InverseMask(mask string) string

计算反掩码 将255.255.255.0 转成0.0.0.255

func IsDomain

func IsDomain(s string) bool

IsDomain 只为s为xxx.xx时为true

func IsDomainName

func IsDomainName(s string) bool

IsDomainName 例s 为localhost 或xxxx.xxx时为true

func IsPrivateIP

func IsPrivateIP(ip string) bool

是否为私网ip

func IsUTF8

func IsUTF8(s string) bool

func MD5

func MD5(s string) string

func MD5WithSalt

func MD5WithSalt(s string, salts ...string) string

func MaskLength

func MaskLength(mask string) int

计算掩码长度 255.255.255.0 得出 24

func OpenFile

func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

func ToASCII

func ToASCII(s string) (string, error)

ToASCII 中文域名转成ascii

func ToUnicode

func ToUnicode(s string) (string, error)

ToUnicode 将s转成中文域名

func UTF8toGBK

func UTF8toGBK(utf8 string) string

func Uint32toIP

func Uint32toIP(ipint uint32) net.IP

Uint32转成net.IP

func Uint32toIPv4

func Uint32toIPv4(ipint uint32) string

Uint32转ip格式

Types

type Field

type Field struct {
	Name string `FieldName:"Name"`
	Type string
}

Field 字段名与类型

func GetFields

func GetFields(o interface{}) []Field

GetFields 获取o的可导出字段(包括匿名)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL