Categorygithub.com/xyzj/toolbox
modulepackage
0.0.0-20241106013813-926841a6acba
Repository: https://github.com/xyzj/toolbox.git
Documentation: pkg.go.dev

# README

golang toolbox

Some useful golang function module codes written by myself, I hope they are also useful to you.

useage: go get -u github.com/xyzj/toolbox

# Packages

Package cache : 数据缓存模块,可定时清理过期数据 Usage package main import ( "github.com/xyzj/toolbox/cache" ) type aaa struct{ Name string } func main() { mycache:=cache.NewEmptyCache[aaa](time.Second*60) // max 1000 data defer mycache.Close() // clean up and stop zhe data expire check mycache.Store("123","abc") v,ok:=mycache.Load("123") if !ok{ println("key not found") return } println(v) } */.
Package config 类ini的配置文件库,支持注释信息.
Package coord 坐标相关功能模块.
Package cron scheduled jobs 定时任务的执行精度为秒,秒的设置为可选,不指定秒时,模块会为你随机设置一个 ┌──────────── second (0-59) 非必填 │ ┌───────────── minute (0–59) 必填 │ │ ┌───────────── hour (0–23) 必填 │ │ │ ┌───────────── day of the month (1–31) 必填,不建议设置大于28,避免2月不执行 │ │ │ │ ┌───────────── month (1–12) 必填 │ │ │ │ │ ┌───────────── day of the week (0–6) (Sunday to Saturday) 必填 * * * * * * 可用的特殊字符 `*`: 表示每一秒/分钟/小时/天/月/周 `,`: 分割指定的时间,如:1,2 `-`: 指定一个区段,如:4-19 `/`: 设置一个指定的周期,一般需要搭配`*`使用,如:*/20.
Package crypto 加密解密.
Package db : 数据库模块,封装了常用方法,可缓存数据,可依据配置自动创建myisam引擎的子表,支持mysql和sqlserver */.
Package email : email emtp发送模块 */.
Package excel excel功能模块.
Package games : 搜罗的一些网页小游戏 try /xgames/ in every go http server build by wlstmicro/v2 */.
Package ginmiddleware 基于gin的web框架封装.
Package gocmd A simplified console program framework that can quickly build a console program.
No description provided by the author
Package logger 日志专用写入器,可设置是否自动依据日期以及文件大小滚动日志文件 */.
Package loopfunc : 用于控制需要持续运行的循环方法,当方法漰溃时会自动重启 */.
Package mapfx 线程安全的字典模块.
Package mq mqtt 和 rmq 相关功能模块.
Package pathtool some path-related methods.
Package proc watch process status.
Package queue safety queue.
Package rate provides a rate limiter.
Package sunriset 日出日落功能模块.
Package txtcode 文本编码转换模块.

# Functions

Base64Imgfile base64码保存为图片.
Base64URLDecode url解码.
Base64UrlSafeEncode url safe 编码.
Bcd2Int8 bcd to int.
Bcd2STime bcd转hh*60+mm.
BcdBytes2Float64 bcd数组转浮点(小端序) b:bcd数组 d:小数位数 Unsigned:无符号的.
BcdBytes2Float64BigOrder bcd数组转浮点(大端序) b:bcd数组 d:小数位数 Unsigned:无符号的.
BcdDT2Stamp bcd时间戳转unix.
Byte2Bytes int8 to bytes.
Byte2Int32s int8 to int32 list.
Byte2Int8 byte转有符号整型.
Byte2SignedInt32 byte转有符号整型 Deprecated: use Byte2Int8().
Bytes use unsafe package conver string to []byte Deprecated: use json.String.
Bytes2Float32 字节数组转单精度浮点,bigOrder==true,高位在前.
Bytes2Float64 字节数组转双精度浮点,bigOrder==true,高位在前.
Bytes2Int64 字节数组转换为int64 b-字节数组 bigorder-是否高位在前 false低位在前.
Bytes2String convert []byte to hex-string args: data: 输入字节切片 sep: 用于分割字符串的分割字符 return: 字符串.
Bytes2Uint64 字节数组转换为uint64 b-字节数组 bigorder-是否高位在前 false低位在前.
CalcCRC32 计算crc32,返回[]byte.
CalcCRC32String 计算crc32,返回16进制字符串.
CalculateSecurityCode calculate security code args: t: calculate type "h"-按小时计算,当分钟数在偏移值范围内时,同时计算前后一小时的值,"m"-按分钟计算,同时计算前后偏移量范围内的值 salt: 拼接用字符串 offset: 偏移值,范围0~59 return: 32位小写md5码切片.
CheckCrc16VB check crc16 data.
CheckCrc16VBBigOrder check crc16 data,use big order.
CheckIP check if the ipstring is legal args: ip: ipstring something like 127.0.0.1:10001 return: true/false.
CheckLrc check lrc data.
CheckRCMru 校验电表数据.
CheckSQLInject 检查sql语句是否包含注入攻击.
CodeString 编码字符串.
CopyFile 复制文件.
CountCrc16VB count crc16 as vb6 do.
CountLrc count lrc data.
CountRCMru 计算电表校验码.
Days2String 将天数转换为年月日显示.
Days2StringCHS 将天数转换为年月日显示.
DecodeString 解码混淆字符串,兼容python算法.
DecodeStringOld 解码混淆字符串,兼容python算法.
DFM2GPS 度分秒转经纬度.
DoRequestWithTimeout 发起请求.
No description provided by the author
EncodeUTF16BE 将字符串编码成utf16be的格式,用于cdma短信发送.
EraseSyncMap 清空sync.map.
ExternalIP 返回v4地址.
ExternalIPV6 返回v6地址.
Float32ToByte 32位浮点转bytes.
Float642BcdBytes 浮点转bcd字节数组(小端序) v:十进制浮点数值 f:格式化的字符串,如"%07.03f","%03.0f".
Float642BcdBytesBigOrder 浮点转bcd字节数组(大端序) v:十进制浮点数值 f:格式化的字符串,如"%07.03f","%03.0f".
Float64ToByte 64位浮点转bytes.
FormatFileSize 字节的单位转换.
FormatFloat64 格式化浮点精度,f-浮点数,p-小数位数.
GetAddrFromString get addr from config string straddr: something like "1,2,3-6" return: []int64,something like []int64{1,2,3,4,5,6}.
GetRandomString 生成随机字符串.
GetTCPPort 获取随机可用端口.
GetUUID1 returns a Version 1 UUID based on the current NodeID and clock sequence, and the current time.
GlobalIPs 返回所有可访问ip ipv4 list,ipv6 list.
GPS2DFM 经纬度转度分秒.
HexString2Bytes 转换hexstring为字节数组 s-hexstring(11aabb) bigorder-是否高位在前 false低位在前.
No description provided by the author
Imgfile2Base64 图片转base64.
Int642Bytes 无符号长整形转换字节数组(8位),bigOrder==true,高位在前.
Int82Bcd int to bcd.
Int82Byte 有符号整型转byte.
IP2Int64 change ip string data to int64 format.
IP2Uint change ip string data to int64 format.
IPInt642Bytes change ip int64 data to string format.
IPInt642String change ip int64 data to string format.
IPUint2Bytes change ip int64 data to string format.
IPUint2String change ip int64 data to string format.
JSON2PB json字符串转pb2格式.
LastSlice 返回切片的最后一个元素.
No description provided by the author
No description provided by the author
PB2Json pb2格式转换为json []byte格式.
PB2String pb2格式转换为json 字符串格式.
RealIP 返回本机的v4或v6ip.
ReverseString ReverseString.
Seconds2String 秒数转换成天,小时,分钟.
Seconds2StringCHS 秒数转换成天,小时,分钟.
SignedBytes2Int64 有符号字节数组转int64,低前.
SignedInt322Byte 有符号整形转byte Deprecated: use Int82Byte().
SlicesDifference 求差集 slice1-并集.
SlicesIntersect 求交集.
SlicesUnion 求并集.
SMSUnicode 编码短信.
SplitDateTime SplitDateTime.
SplitStringWithLen 按制定长度分割字符串 s-原始字符串 l-切割长度.
Stamp2BcdDT unix时间戳转bcd,6字节,第一字节为秒.
Stamp2Time convert stamp to datetime string.
STime2Bcd hh*60+mm转BCD.
String use unsafe package conver []byte to string Deprecated: use json.String.
String2Byte convert string 2 one byte args: s: 输入字符串 t: 返回数值进制 Return: byte.
String2Bytes convert hex-string to []byte args: data: 输入字符串 sep: 用于分割字符串的分割字符 return: 字节切片.
String2Float32 convert string 2 float64.
String2Float64 convert string 2 float64.
String2Int convert string 2 int args: s: 输入字符串 t: 返回数值进制 Return: int.
String2Int32 convert string 2 int32 args: s: 输入字符串 t: 返回数值进制 Return: int32.
String2Int64 convert string 2 int64 args: s: 输入字符串 t: 返回数值进制 Return: int64.
String2Int8 convert string 2 int8 args: s: 输入字符串 t: 返回数值进制 Return: int8.
String2UInt64 convert string 2 uint64 args: s: 输入字符串 t: 返回数值进制 Return: uint64.
String2Unicode 字符串转4位unicode编码.
StringSlice2Int8 convert string Slice 2 int8.
SwapCase swap char case.
SwitchStamp switch stamp format between unix and c#.
Time2Stamp convert datetime string to stamp.
Time2Stampf 可根据制定的时间格式和时区转换为当前时区的Unix时间戳 s:时间字符串 fmt:时间格式 year:2006,month:01,day:02 hour:15,minute:04,second:05 tz:0~12,超范围时使用本地时区.
Time2StampNB 电信NB平台数据时间戳转为本地unix时间戳.
TrimString 去除字符串末尾的空格,\r\n.
Uint642Bytes 长整形转换字节数组(8位),bigOrder==true,高位在前.
UnZIPFile 解压缩文件.
VersionInfo show something name: program name ver: program version gover: golang version buildDate: build datetime buildOS: platform info auth: auth name.
WriteVersionInfo write version info to .ver file args: p: program name v: program version gv: golang version bd: build datetime pl: platform info a: auth name.
ZIPFile 压缩文件.
ZIPFiles 压缩多个文件.

# Constants

DateOnlyFormat yyyy-mm-dd.
DateTimeFormat yyyy-mm-dd hh:MM:ss.
日志文件命名格式.
LongTimeFormat 含日期的日志内容时间戳格式 2006-01-02 15:04:05.000.
OSARCH from runtime.
OSNAME from runtime.
ShortTimeFormat 无日期的日志内容时间戳格式 15:04:05.000.
TimeOnlyFormat hh:MM:ss.

# Variables

DefaultCacheDir 默认缓存文件夹.
DefaultConfDir 默认配置文件夹.
DefaultLogDir 默认日志文件夹.

# Structs

No description provided by the author
StringSliceSort 字符串数组排序.

# Type aliases

A Time represents a time as the number of 100's of nanoseconds since 15 Oct 1582.