modulepackage
0.0.0-20190129081739-38e990d849fc
Repository: https://github.com/luopengift/types.git
Documentation: pkg.go.dev
# Functions
BytesToMap []byte => map[string]interface{}.
BytesToString byte => string 直接转换底层指针,两者指向的相同的内存,改一个另外一个也会变。 效率是string(Bytes{})的百倍以上,且转换量越大效率优势越明显。.
CallFuncName call func name.
CallMethodName Call method by name Example: type Test struct { i int j int } func (t *Test) Add(i int) (int,error) { return t.i+t.j+i, nil } var T = &Test{1,2} CallMethodName(T,"Add",1) // [4 <nil>] <nil>.
Clean 清理#注释.
DurationHuman duration human.
FileToBytes file => []byte.
FileToMap file => map[string]interface{}.
Format implement Formatter interface map[string]interface{} => struct{} eg: Format(map[string]interface{...}, &Struct{}).
FormatINI format ini.
FormatJSON format json.
FormatXML format xml.
FormatYAML format yaml.
FuncWithTimeout func timeout.
MapToBytes map[string]interface{} => []byte.
NewSortMap sortmap.
Now now.
ParseConfigFile parse config file.
ParseConfigFiles parse config files.
Round float64四舍五入,并取前几位.
StringToBool string => bool, if fail return false.
StringToBytes string => Bytes 直接转换底层指针,两者指向的相同的内存,改一个另外一个也会变。 效率是string(Bytes{})的百倍以上,且转换量越大效率优势越明显。 转换之后若没做其他操作直接改变里面的字符,则程序会崩溃。 如 b:=String2bytes("xxx"); b[1]='d'; 程序将panic。.
StringToFloat64 string => float64, if fail return 0.
StringToInt string => int, if fail return 0.
StringToInt64 string => int64, if fail return 0.
StringToMap string => map[string]interface{}.
TimeFormat time string.
ToBool interface => bool.
ToBytes interface => []byte.
ToFloat64 interface => float64.
ToInt interface => int.
ToInt64 interface => int64.
ToJSON to json.
ToList interface => []interface.
ToMap interface => map[string]interface{}.
ToString interface => string.
ToXML to json.
ToYAML 将结构体in转换成yml格式的字符串, 适用于配置文件落地.