# README
Go-Utils Go语言常用公共函数收集
安装
go get -u github.com/maczh/utils
包含工具包
- 3DES加解密
- AES加解密
- DES加解密
- BASE64编码解码
- RSA加密解密签名验签
- MD5摘要算法
- SHA摘要算法
- JSON序列化与反序列化
- 文件与目录操作
- 常用字符串验证:手机号、email、昵称、用户名、中文名等
- 条件判断函数
- 文件下载工具
- emoji表情工具
- Gin获取Post和Get全部参数 x-www-form-urlencoded
- hashset
- IP和端口工具
- Map转换、排序、判断key是否存在
- 随机字符串工具
- uuid生成工具
- SFTP上传下载工具
- 数组切片工具
- 字符串工具
- 中文工具:判断是否中文、中文字数、中文取子串、GBK/UTF-8互转
- 结构体与map互转工具
- 运行外部程序工具
- 时间格式转换
- URL编码反编码
- XML与map互转工具
- zip压缩工具
# Functions
No description provided by the author
No description provided by the author
AddString 拼接字符串.
AddStringBytes 拼接字符串, 返回 bytes from bytes.Join().
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
[]int => []string.
[]string => []int.
No description provided by the author
No description provided by the author
get filepath base name.
BytePos alias of the strings.IndexByte.
Center justifies the text in the center.
CheckSqlValidate 检查是否含有可能产生注入的非法字符 返回值为true时表示含有非法字符,同时返回的字符串值为匹配到的非法字符.
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
CompactJSON compact json input with insignificant space characters elided.
Compress returns compressed bytes.
No description provided by the author
No description provided by the author
Format time.Time struct to string MM - month - 01 M - month - 1, single bit DD - day - 02 D - day 2 YYYY - year - 2006 YY - year - 06 HH - 24 hours - 03 H - 24 hours - 3 hh - 12 hours - 03 h - 12 hours - 3 mm - minute - 04 m - minute - 4 ss - second - 05 s - second = 5.
全角转半角.
DecodeXMLToMap decodes xml reading from io.Reader and returns the first-level sub-node key-value set, if the first-level sub-node contains child nodes, skip it.
Decompress returns the decompressed bytes.
No description provided by the author
DefaultIfNil checks if the value is nil, if true returns the default value otherwise the original.
删除数组.
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
求差集 slice1-并集.
get filepath dir name.
list dirs under dirPath.
No description provided by the author
No description provided by the author
EncodeXMLFromMap encodes map[string]string to io.Writer with xml format.
No description provided by the author
No description provided by the author
No description provided by the author
计算文件的MD5值.
get file modified time.
No description provided by the author
get file size as how many bytes.
list files under dirPath.
FirstNonNil returns the first non nil parameter.
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
Get0Hour 当天 0 点.
Get0LastMonth 上月第一天 0 点.
Get0LastWeek 上周一 0 点.
Get0Minute 0 分.
Get0Month 当月第一天 0 点.
Get0NextMonth 下月第一天 0 点.
Get0NextWeek 下周一 0 点.
Get0Second 0 秒.
Get0Tomorrow 昨天 0 点.
Get0Week 本周一 0 点.
Get0Yesterday 昨天 0 点.
No description provided by the author
No description provided by the author
GetIPv4ByInterface return IPv4 address from a specific interface IPv4 addresses.
No description provided by the author
GetMonthDays 当月天数.
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
GinParamMap 获取请求参数,转成Map.
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
IfThen evaluates a condition, if true returns the parameters otherwise nil.
IfThenElse evaluates a condition, if true returns the first parameter otherwise the second.
No description provided by the author
Int64Unique 去重.
No description provided by the author
No description provided by the author
求交集.
IsAlphabet char.
IsAlphaNum reports whether the byte is an ASCII letter, number, or underscore.
IsBlank returns true if the string is blank (all whitespace).
IsBlankBytes returns true if the given []byte is all space characters.
检验是否为合法的中国手机号, 不是那么太精细 只要是 13,14,15,18 开头的 11 位数字就认为是中国手机号.
同 func IsChinaMobile(b []byte) bool.
No description provided by the author
IsChineseName 检验是否为有效的中文姓名(比如 张三, 李四, 张三·李四).
IsChineseNameEx 检验是否为有效的中文姓名(比如 张三, 李四, 张三·李四), 主要功能和 IsChineseName 相同, 但是如果姓名中包含不规范的间隔符, 会自动修正为正确的间隔符 '\u00B7', 并返回正确的结果.
同 IsChineseName(b []byte) bool.
同 IsChineseNameEx(b []byte) ([]byte, bool).
IsDir 目录是否存在.
IsEmpty returns true if the string is empty.
IsEndOf alias of the strings.HasSuffix.
IsExist checks whether a file or directory exists.
IsFile checks whether the path is a file, it returns false when it's a directory or does not exist.
判断是否是18或15位身份证.
No description provided by the author
检验是否为合法的电子邮箱, 考虑到各个网站的 mail 要求不一样, 这里匹配比较宽松 邮箱用户名可以包含 0-9, A-Z, a-z, -, _, .
同 func IsMail(b []byte) bool.
IsMark determines whether the rune is a marker.
检验是否为合法的昵称, 合法的字符有 0-9, A-Z, a-z, _, 汉字 字符 '_' 只能出现在中间且不能重复, 如 "__".
同 func IsNickname(b []byte) bool.
IsNotBlank returns true if the string is not blank.
IsNotEmpty returns true if the string is not empty.
IsNumeric returns true if the given character is a numeric, otherwise false.
IsPortUse 判断端口是否被占用.
IsSpace returns true if the given character is a space, otherwise false.
IsSpaceRune returns true if the given rune is a space, otherwise false.
IsStartOf alias of the strings.HasPrefix.
检验是否为合法的用户名, 合法的字符有 0-9, A-Z, a-z, _ 第一个字母不能为 _, 0-9 最后一个字母不能为 _, 且 _ 不能连续.
同 func IsName(b []byte) bool.
IsValidUUIDString returns true, if the given string matches a valid UUID (version 4, variant 2).
JSONPrettyPrint pretty print raw json string to indent string.
No description provided by the author
Left justifies the text to the left.
Length counts the input while respecting UTF8 encoding and combined characters.
单机时间滑动窗口限流法.
LocalIPs return all non-loopback IPv4 addresses.
No description provided by the author
LowerFirst lower first char.
map转换.
No description provided by the author
map转换.
No description provided by the author
MustNewUUID returns a new uuid, if an error occurs it panics.
NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.
NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.
No description provided by the author
No description provided by the author
NewSafeGo 创建一个安全的协程调用
示例:
safeGo := NewSafeGo(func(args ...any) {
})
safeGo.SetGoBeforeHandler(func() map[string]any {
return map[string]any{
"preRoutineId": "123",
}
})
safeGo.SetCallBeforeHandler(func(params map[string]any) {
fmt.Println(params["preRoutineId"])
})
safeGo.Run("hello", "world")
*/.
NewUUID generates a new version 4 UUID relying only on random numbers.
No description provided by the author
No description provided by the author
No description provided by the author
私钥解密.
私钥加密.
公钥解密.
公钥加密.
ReadFileToBytes reads data type '[]byte' from file by given path.
ReadFileToString reads data type 'string' from file by given path.
get absolute filepath, based on built executable file.
rename file name.
No description provided by the author
No description provided by the author
No description provided by the author
Right justifies the text to the right.
RunePos alias of the strings.IndexRune.
Search a file in paths.
SelfDir gets compiled executable file directory.
SelfPath gets compiled executable file absolute path.
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
SliceMerge merges interface slices to one slice.
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
No description provided by the author
No description provided by the author
No description provided by the author
StringUnique 去重.
StrPos alias of the strings.Index.
Struct2Map return map.
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
清除emoji表情.
str[TrimSpace] in string list.
3DES解密.
No description provided by the author
3DES加密.
No description provided by the author
[golang ECB 3DES Decrypt].
[golang ECB 3DES Encrypt].
表情转换.
表情解码.
No description provided by the author
delete file.
No description provided by the author
Uppercase alias of the strings.ToUpper().
UpperFirst upper first char.
UpperWord Change the first character of each word to uppercase.
No description provided by the author
No description provided by the author
Utf8Len of the string.
No description provided by the author
No description provided by the author
ValidUtf8String check.
WaitNextMinute 下一分钟, 对齐时间, 0 秒.
判断时间是当年的第几周.
WriteBytesToFile saves content type '[]byte' to file by given path.
WriteStringFile saves content type 'string' to file by given path.
No description provided by the author
No description provided by the author
ZIP压缩多个文件,带批量修改压缩包里的文件名功能.
# Variables
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
regex for validating that the UUID matches RFC 4122.
# Structs
No description provided by the author
No description provided by the author
按值排序.
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
UUID represent a universal identifier with 16 octets.