package
0.1.4
Repository: https://github.com/mangenotwork/common.git
Documentation: pkg.go.dev

# README

常用实用方法

类型转换 AnyToString any -> string

func AnyToString(i interface{}) string


类型转换 JsonToMap json -> map

func JsonToMap(str string) (map[string]interface{}, error)


类型转换 MapToJson map -> json

func MapToJson(m interface{}) (string, error)


类型转换 AnyToMap interface{} -> map[string]interface{}

func AnyToMap(data interface{}) map[string]interface{}


类型转换 AnyToInt interface{} -> int

func AnyToInt(data interface{}) int


类型转换 AnyToInt64 interface{} -> int64

func AnyToInt64(data interface{}) int64


类型转换 AnyToArr interface{} -> []interface{}

func AnyToArr(data interface{}) []interface{}


类型转换 AnyToFloat64 interface{} -> float64

func AnyToFloat64(data interface{}) float64


类型转换 AnyToStrings interface{} -> []string

func AnyToStrings(data interface{}) []string


类型转换 AnyToJson interface{} -> json string

func AnyToJson(data interface{}) (string, error)


类型转换 IntToHex int -> hex

func IntToHex(i int) string


类型转换 Int64ToHex int64 -> hex

func Int64ToHex(i int64) string


类型转换 HexToInt hex -> int

func HexToInt(s string) int


类型转换 HexToInt64 hex -> int

func HexToInt64(s string) int64


类型转换 StrNumToInt64 string -> int64

func StrNumToInt64(str string) int64


类型转换 StrNumToInt string -> int

func StrNumToInt(str string) int


类型转换 StrNumToInt32 string -> int32

func StrNumToInt32(str string) int32


类型转换 StrNumToFloat64 string -> float64

func StrNumToFloat64(str string) float64


类型转换 StrNumToFloat32 string -> float32

func StrNumToFloat32(str string) float32


类型转换 Uint8ToStr []uint8 -> string

func Uint8ToStr(bs []uint8) string


类型转换 StrToByte string -> []byte

func StrToByte(s string) []byte


类型转换 ByteToStr []byte -> string

func ByteToStr(b []byte) string


类型转换 BoolToByte bool -> []byte

func BoolToByte(b bool) []byte


类型转换 ByteToBool []byte -> bool

func ByteToBool(b []byte) bool


类型转换 IntToByte int -> []byte

func IntToByte(i int) []byte


类型转换 ByteToInt []byte -> int

func ByteToInt(b []byte) int


类型转换 func Int64ToByte(i int64) []byte

func Int64ToByte(i int64) []byte


类型转换 ByteToInt64 []byte -> int64

func ByteToInt64(b []byte) int64


类型转换 Float32ToByte float32 -> []byte

func Float32ToByte(f float32) []byte


类型转换 Float32ToUint32 float32 -> uint32

func Float32ToUint32(f float32) uint32


类型转换 ByteToFloat32 []byte -> float32

func ByteToFloat32(b []byte) float32


类型转换 Float64ToByte float64 -> []byte

func Float64ToByte(f float64) []byte


类型转换 Float64ToUint64 float64 -> uint64

func Float64ToUint64(f float64) uint64


类型转换 ByteToFloat64 []byte -> float64

func ByteToFloat64(b []byte) float64


类型转换 StructToMap struct -> map[string]interface{}

func StructToMap(obj interface{}) map[string]interface{}


EncodeByte encode byte

func EncodeByte(v interface{}) []byte


DecodeByte decode byte

func DecodeByte(b []byte) (interface{}, error)


类型转换 ByteToBit []byte -> []uint8 (bit)

func ByteToBit(b []byte) []uint8


类型转换 BitToByte []uint8 -> []byte

func BitToByte(b []uint8) []byte


类型转换 StructToMapV2 Struct -> map

func StructToMapV2(obj interface{}, hasValue bool) (map[string]interface{}, error)

参数

hasValue=true表示字段值不管是否存在都转换成map
hasValue=false表示字段为不为空或者不为0则转换成map

类型转换 StructToMapV3 struct -> map

func StructToMapV3(obj interface{}) map[string]interface{}


类型转换 PanicToError panic -> error

func PanicToError(fn func()) (err error)


类型转换 P2E panic -> error

func P2E()


类型转换 ByteToBinaryString 字节 -> 二进制字符串

func ByteToBinaryString(data byte) (str string)


类型转换 MapStrToAny map[string]string -> map[string]interface{}

func MapStrToAny(m map[string]string) map[string]interface{}


类型转换 ByteToGBK byte -> gbk byte

func ByteToGBK(strBuf []byte) []byte


类型转换 Int64ToStr int64 -> string

func Int64ToStr(i int64) string


































# Functions

AbPathByCaller 获取当前执行文件绝对路径(go run).
AnyToArr interface{} -> []interface{}.
AnyToFloat64 interface{} -> float64.
AnyToInt interface{} -> int.
AnyToInt64 interface{} -> int64.
AnyToJson interface{} -> json string.
AnyToJsonB interface{} -> json string.
AnyToMap interface{} -> map[string]interface{}.
AnyToString any -> string.
AnyToStrings interface{} -> []string.
Base64Decode base64 解码.
Base64Encode base64 编码.
Base64UrlDecode base64 url 解码.
Base64UrlEncode base64 url 编码.
BeginDayUnix 获取当天 0点.
BIG5To big to.
BitToByte []uint8 -> []byte.
BoolToByte bool -> []byte.
ByteToBinaryString 字节 -> 二进制字符串.
ByteToBit []byte -> []uint8 (bit).
ByteToBool []byte -> bool.
ByteToFloat32 []byte -> float32.
ByteToFloat64 []byte -> float64.
ByteToGBK byte -> gbk byte.
ByteToInt []byte -> int.
ByteToInt64 []byte -> int64.
ByteToStr []byte -> string.
CleaningStr 清理字符串前后空白 和回车 换行符号.
CompressDirZip 压缩目录.
CompressFiles 压缩很多文件 files 文件数组,可以是不同dir下的文件或者文件夹 dest 压缩文件存放地址.
ConvertByte2String 编码转换.
ConvertGBKToStr 将GBK编码的字符串转换为utf-8编码.
ConvertStrToGBK 将utf-8编码的字符串转换为GBK编码.
No description provided by the author
DayAgo 获取多少天前的时间戳.
DayAgoDate 获取多少天前的时间戳.
No description provided by the author
DayDiff 两个时间字符串的日期差.
当前时间戳在今天是否结束.
DecodeByte decode byte.
DecompressionZipFile zip压缩文件.
DeCompressTAR tar 解压文件.
DeCompressZIP zip解压文件.
DeepCopy 深copy.
DeepEqual 深度比较任意类型的两个变量的是否相等,类型一样值一样反回true 如果元素都是nil,且类型相同,则它们是相等的; 如果它们是不同的类型,它们是不相等的.
EncodeByte encode byte.
EndDayUnix 获取当天 24点.
Exists 路径是否存在.
FileExists 文件是否存在.
FileMd5 file md5 文件md5.
FileMd5sum 文件 Md5.
Float32ToByte float32 -> []byte.
Float32ToUint32 float32 -> uint32.
Float64ToByte float64 -> []byte.
Float64ToUint64 float64 -> uint64.
GB18030To gb18030 to.
GB2312To gb2312 to.
GDKTo gdk to.
Get16MD5Encode 返回一个16位md5加密后的字符串.
GetAllFile 获取目录下的所有文件.
GetChineseMonthDay 获取农历.
GetMD5Encode 获取Md5编码.
GetNowPath 获取当前运行路径.
GetPointClassHTML 获取指定标签class属性的html.
GetPointHTML 获取指定位置的HTML, 用标签, 标签属性, 属性值来定位.
GetPointIDHTML 获取指定标签id属性的html.
GetWD 获取当前工作目录.
GzipCompress gzip压缩.
GzipDecompress gzip解压.
HexToInt hex -> int.
HexToInt64 hex -> int.
HmacMD5 hmac md5.
HmacSHA1 hmac sha1.
HmacSHA256 hmac sha256.
HmacSHA512 hmac sha512.
HourAgo 获取多少小时前的时间戳.
HZGB2312To hzgb2312 to.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
IF 三元表达式 use: IF(a>b, a, b).(int).
Int64ToByte int64 -> []byte.
Int64ToHex int64 -> hex.
Int64ToStr int64 -> string.
IntToByte int -> []byte.
IntToHex int -> hex.
IsContainStr 字符串是否等于items中的某个元素.
IsDir 是否是目录.
IsElementStr 判断字符串是否与数组里的某个字符串相同.
IsFile 是否是文件.
IsHaveKey map[string]interface{} 是否存在 输入的key.
IsJson 是否是json格式.
IsLeap 是否是闰年.
IsPic 判断是否是图片.
IsToday 判断是否是今天 "2006-01-02 15:04:05" timestamp 需要判断的时间.
IsTodayList 列表页的时间显示 "01-02 15:04".
IsUtf8 是否是utf8编码.
JsonFind 按路径寻找指定json值 用法参考 ./_examples/json/main.go @find : 寻找路径,与目录的url类似, 下面是一个例子: json: {a:[{b:1},{b:2}]} find=/a/[0] => {b:1} find=a/[0]/b => 1.
JsonFind2Arr 寻找json,输出 []interface{}.
JsonFind2Json 寻找json,输出 json格式字符串.
JsonFind2Map 寻找json,输出 map[string]interface{}.
JsonToMap json -> map.
LatestDate 最近好多天.
Map2Slice Eg: {"K1": "v1", "K2": "v2"} => ["K1", "v1", "K2", "v2"].
No description provided by the author
No description provided by the author
MapStrToAny map[string]string -> map[string]interface{}.
MapToJson map -> json.
No description provided by the author
MinuteAgo 获取多少分钟前的时间戳.
NewAES : use NewAES(AES_CBC).
No description provided by the author
NewDES : use NewDES(DES_CBC).
NewGDMap ues: NewGDMap().Add(k,v).
No description provided by the author
NewPaginator 创建分页.
No description provided by the author
NewShortCode 获取一个不重复的短code;常用与短链code生成;.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NowToEnd 计算当前时间到这天结束还有多久.
OrderMap ues: OrderMap[K, V]().
OutJsonFile 将data输出到json文件.
P2E panic -> error.
PanicToError panic -> error.
PathExists 目录不存在则创建.
No description provided by the author
RandomIntCaptcha 生成 captchaLen 位随机数,理论上会重复.
No description provided by the author
No description provided by the author
No description provided by the author
ReplaceAllToOne 批量统一替换字符串.
ResolveTime 将传入的“秒”解析为3种时间单位.
No description provided by the author
SearchBytesIndex []byte 字节切片 循环查找.
SizeFormat 字节的单位转换 保留两位小数.
Slice2Map ["K1", "v1", "K2", "v2"] => {"K1": "v1", "K2": "v2"} ["K1", "v1", "K2"] => nil.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
StrDeleteSpace 删除字符串前后的空格.
StrDuplicates 数组,切片去重和去空串.
StrLen 获取字符长度.
StrNumToFloat32 string -> float32.
StrNumToFloat64 string -> float64.
StrNumToInt string -> int.
StrNumToInt32 string -> int32.
StrNumToInt64 string -> int64.
StrToByte string -> []byte.
StructToMap struct -> map[string]interface{}.
StructToMapV2 Struct -> map hasValue=true表示字段值不管是否存在都转换成map hasValue=false表示字段为不为空或者不为0则转换成map.
StructToMapV3 struct -> map.
TickerRun 间隔运行 t: 间隔时间, runFirst: 间隔前或者后执行 f: 运行的方法.
Timestamp 获取时间戳.
No description provided by the author
No description provided by the author
No description provided by the author
ToBIG5 to big5.
ToGB18030 to gb18030.
ToGB2312 to gb2312.
ToGDK to gdk.
ToHZGB2312 to hzgb2312.
ToUTF16 to utf16.
ToUTF8 to utf8.
Uint8ToStr []uint8 -> string.
UnescapeUnicode Unicode 转码.
No description provided by the author
No description provided by the author
No description provided by the author
UTF16To utf16 to.
UTF8To utf8 to.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
定义每天的秒数.
定义每小时的秒数.
定义每分钟的秒数.
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

Leaps 闰年的天数.
Pyears 平年天数.

# Structs

Bar 终端显示的进度条.
No description provided by the author
GDMap 固定顺序map.
No description provided by the author
No description provided by the author
Paginator 分页器.
No description provided by the author

# Interfaces

AES AES interface.
DES DES interface.
GDMaper 固定顺序 Map 接口.

# Type aliases

Charset 字符集类型.
No description provided by the author