Documentation
¶
Overview ¶
Package toolbox : 收集,保存的一些常用方法
Index ¶
- Constants
- Variables
- func Base64Decode(data string) ([]byte, error)
- func Base64Imgfile(b, f string) error
- func Base64URLDecode(data string) ([]byte, error)
- func Bcd2Int8(v byte) byte
- func Bcd2STime(b []byte) int32
- func BcdBytes2Float64(b []byte, decimal int, unsigned bool) float64
- func BcdBytes2Float64BigOrder(b []byte, decimal int, unsigned bool) float64
- func BcdDT2Stamp(d []byte) int64
- func Byte2Bytes(v byte, reverse bool) []byte
- func Byte2Int8(b byte) int8
- func Byte2Int32s(v byte, reverse bool) []int32
- func Byte2SignedInt32(b byte) int32deprecated
- func Bytes(s string) []bytedeprecated
- func Bytes2Float32(b []byte, bigOrder bool) float32
- func Bytes2Float64(b []byte, bigOrder bool) float64
- func Bytes2Int64(b []byte, bigorder bool) int64
- func Bytes2String(data []byte, sep string) string
- func Bytes2Uint64(b []byte, bigorder bool) uint64
- func CalcCRC32(b []byte, bigorder bool) []byte
- func CalcCRC32String(b []byte) string
- func CalculateSecurityCode(t, salt string, offset int) []string
- func CheckCrc16VB(d []byte) bool
- func CheckCrc16VBBigOrder(d []byte) bool
- func CheckIP(ip string) bool
- func CheckLrc(d []byte) bool
- func CheckRCMru(d []byte) bool
- func CheckSQLInject(s string) bool
- func CodeString(s string) string
- func CopyFile(src, dst string) (int64, error)
- func CountCrc16VB(data *[]byte) []byte
- func CountLrc(data *[]byte) byte
- func CountRCMru(d []byte) byte
- func DFM2GPS(du, fen int, miao float64) float64
- func Days2String(days int) string
- func Days2StringCHS(days int) string
- func DecodeString(s string) string
- func DecodeStringOld(s string) string
- func DoRequestWithTimeout(req *http.Request, timeo time.Duration) (int, []byte, map[string]string, error)
- func DoStreamRequest(req *http.Request, header func(map[string]string), recv func([]byte) error, ...) error
- func DumpReqBody(req *http.Request) ([]byte, error)
- func EncodeUTF16BE(s string) []byte
- func EraseSyncMap(m *sync.Map)
- func Float32ToByte(float float32) []byte
- func Float32ToByteBig(float float32) []byte
- func Float64ToByte(float float64) []byte
- func Float64ToByteBig(float float64) []byte
- func Float642BcdBytes(v float64, f string) []byte
- func Float642BcdBytesBigOrder(v float64, f string) []byte
- func FormatBytes(bytes int64) string
- func FormatDuration(seconds int64, opts ...DurationOptions) string
- func FormatFileSize(byteSize uint64) (size string)
- func FormatFloat64(f float64, p int) float64
- func GPS2DFM(l float64) (int, int, float64)
- func GbkToUtf8(s []byte) ([]byte, error)
- func GetAddrFromString(straddr string) ([]int64, error)
- func GetFirstLocalIP(preferIPv6 bool) (string, error)
- func GetLocalIPs(ipv6 bool) ([]string, error)
- func GetRandomString(l int64, letteronly ...bool) string
- func GetTCPPort() (int, error)
- func GetUUID1() string
- func HTTPBasicAuth(namemap map[string]string, next http.HandlerFunc) http.HandlerFunc
- func HexString2Bytes(s string, bigorder bool) []byte
- func IP2Int64(ipnr string) int64
- func IP2Uint(ipnr string) uint
- func IPInt642Bytes(ipnr int64) []byte
- func IPInt642String(ipnr int64) string
- func IPUint2Bytes(ipnr int64) []byte
- func IPUint2String(ipnr uint) string
- func IPv6ToInt32Segments(s string) ([]byte, error)
- func Imgfile2Base64(s string) (string, error)
- func Int32SegmentsToIPv6(b []byte) (string, error)
- func Int82Bcd(v byte) byte
- func Int82Byte(i int8) byte
- func Int642Bytes(i int64, bigOrder bool) []byte
- func IsValidIP(ipStr string) (string, bool)
- func JSON2PB(js string, pb interface{}) error
- func LastSlice(s, sep string) string
- func LeftPadZeros(s string, totalLen int) string
- func PB2Json(pb interface{}) []byte
- func PB2String(pb interface{}) string
- func ParseNumberRange(input string) ([]int64, error)
- func RealIP(v6first bool) string
- func RemoveUnvisiable(s string) string
- func ReverseString(s string) string
- func SMSUnicode(s string) []string
- func STime2Bcd(t int32) []byte
- func Seconds2String(sec int64) string
- func Seconds2StringCHS(sec int64) string
- func SignedBytes2Int64(b []byte) int64
- func SignedInt322Byte(i int32) bytedeprecated
- func SlicesDifference(slice1, slice2 []string) []string
- func SlicesIntersect(slice1, slice2 []string) []string
- func SlicesUnion(slice1, slice2 []string) []string
- func SplitDateTime(sdt int64) (y, m, d, h, mm, s, wd byte)
- func SplitStringWithLen(s string, l int) []string
- func Stamp2BcdDT(dt int64) []byte
- func Stamp2Time(t int64, fmt ...string) string
- func String(b []byte) stringdeprecated
- func String2Byte(s string, t int) byte
- func String2Bytes(data string, sep string) []byte
- func String2Float32(s string) float32
- func String2Float64(s string) float64
- func String2Int(s string, t int) int
- func String2Int8(s string, t int) byte
- func String2Int32(s string, t int) int32
- func String2Int64(s string, t int) int64
- func String2UInt64(s string, t int) uint64
- func String2Unicode(s string) string
- func StringSlice2Int8(bs []string) byte
- func StringToFixedRightPad(s string, n int) []byte
- func SwapCase(s string) string
- func SwitchStamp(t int64) int64
- func Time2Stamp(s string) int64
- func Time2StampNB(s string) int64
- func Time2Stampf(s, fmt string, tz float32) int64
- func TrimString(s string) string
- func Uint642Bytes(i uint64, bigOrder bool) []byte
- func UnZIPFile(archive, target string) error
- func Utf8ToGbk(s []byte) ([]byte, error)
- func ValidateIPPort(s string) (*net.TCPAddr, bool)
- func WriteVersionInfo(p, v, gv, bd, pl, a string)
- func ZIPFile(d, s string, delold bool) error
- func ZIPFiles(dstName string, srcFiles []string, newDir string) error
- type DurationOptions
- type FlexibleInt64
- type StringSliceSort
- type Time
Constants ¶
const ( // OSNAME from runtime OSNAME = runtime.GOOS // OSARCH from runtime OSARCH = runtime.GOARCH // DateTimeFormat yyyy-mm-dd hh:MM:ss DateTimeFormat = "2006-01-02 15:04:05" // DateOnlyFormat yyyy-mm-dd DateOnlyFormat = "2006-01-02" // TimeOnlyFormat hh:MM:ss TimeOnlyFormat = "15:04:05" // LongTimeFormat 含日期的日志内容时间戳格式 2006-01-02 15:04:05.000 LongTimeFormat = "2006-01-02 15:04:05.000" // ShortTimeFormat 无日期的日志内容时间戳格式 15:04:05.000 ShortTimeFormat = "15:04:05.000" // FileTimeFormat 日志文件命名格式 060102 FileTimeFormat = "060102" // 日志文件命名格式 )
Variables ¶
var ( TimeUnitsZh = timeUnits{ Day: "天", Hour: "小时", Minute: "分钟", Second: "秒", LessThanOneMinute: "不到1分钟", } TimeUnitsEn = timeUnits{ Day: " day", Hour: " hour", Minute: " minute", Second: " second", LessThanOneMinute: "less than 1 minute", } )
var ( // DefaultLogDir 默认日志文件夹 DefaultLogDir = filepath.Join(pathtool.GetExecDir(), "..", "log") // DefaultCacheDir 默认缓存文件夹 DefaultCacheDir = filepath.Join(pathtool.GetExecDir(), "..", "cache") // DefaultConfDir 默认配置文件夹 DefaultConfDir = filepath.Join(pathtool.GetExecDir(), "..", "conf") )
Functions ¶
func Base64Decode ¶
Base64Decode decodes a base64 encoded string into a byte slice.
The function takes a single parameter: - data: A string representing the base64 encoded data.
The function returns two values: - []byte: A byte slice containing the decoded data. - error: An error if the decoding process fails. If the decoding is successful, the error will be nil.
func Byte2SignedInt32
deprecated
func Bytes2Float32 ¶
Bytes2Float32 字节数组转单精度浮点,bigOrder==true,高位在前
func Bytes2Float64 ¶
Bytes2Float64 字节数组转双精度浮点,bigOrder==true,高位在前
func Bytes2String ¶
Bytes2String convert []byte to hex-string
args: data: 输入字节切片 sep: 用于分割字符串的分割字符 return: 字符串
func CalculateSecurityCode ¶
CalculateSecurityCode calculate security code
args: t: calculate type "h"-按小时计算,当分钟数在偏移值范围内时,同时计算前后一小时的值,"m"-按分钟计算,同时计算前后偏移量范围内的值 salt: 拼接用字符串 offset: 偏移值,范围0~59 return: 32位小写md5码切片
func CheckCrc16VBBigOrder ¶
CheckCrc16VBBigOrder check crc16 data,use big order
func CheckIP ¶
CheckIP check if the ipstring is legal
args: ip: ipstring something like 127.0.0.1:10001 return: true/false
func DoRequestWithTimeout ¶
func DoRequestWithTimeout(req *http.Request, timeo time.Duration) (int, []byte, map[string]string, error)
DoRequestWithTimeout 发起请求
func DoStreamRequest ¶
func DoStreamRequest(req *http.Request, header func(map[string]string), recv func([]byte) error, opts ...httpclient.ReqOptions) error
func Float642BcdBytesBigOrder ¶
Float642BcdBytesBigOrder 浮点转bcd字节数组(大端序)
v:十进制浮点数值 f:格式化的字符串,如"%07.03f","%03.0f"
func FormatDuration ¶
func FormatDuration(seconds int64, opts ...DurationOptions) string
FormatDuration 接受秒数和一个可选的 DurationOptions 结构体 将秒数转换为 xx天xx小时xx分钟xx秒 的可读格式。
func FormatFloat64 ¶
FormatFloat64 格式化浮点精度,f-浮点数,p-小数位数
func GetAddrFromString ¶
GetAddrFromString get addr from config string
straddr: something like "1,2,3-6" return: []int64,something like []int64{1,2,3,4,5,6}
func GetFirstLocalIP ¶
GetFirstLocalIP 返回首个匹配的本机地址,找不到时返回空字符串和错误。 优先 IPv4(preferIPv6=false),可通过 preferIPv6 改变优先级。
func GetLocalIPs ¶
GetLocalIPs 返回本机所有网卡绑定的 IPv4 或 IPv6 地址(不包含回环或未启用接口)。 参数 ipv6 = true 则返回 IPv6 地址,否则返回 IPv4 地址。 会过滤:未启用接口、loopback、未指定地址(0.0.0.0 / ::)、链路本地地址(如 fe80::/10)。
func GetRandomString ¶
GetRandomString 生成随机字符串
func GetUUID1 ¶
func GetUUID1() string
GetUUID1 returns a Version 1 UUID based on the current NodeID and clock sequence, and the current time. If the NodeID has not been set by SetNodeID or SetNodeInterface then it will be set automatically. If the NodeID cannot be set NewUUID returns nil. If clock sequence has not been set by SetClockSequence then it will be set automatically. If GetTime fails to return the current NewUUID returns nil and an error.
In most cases, New should be used.
func HTTPBasicAuth ¶
func HTTPBasicAuth(namemap map[string]string, next http.HandlerFunc) http.HandlerFunc
func HexString2Bytes ¶
HexString2Bytes 转换hexstring为字节数组
s-hexstring(11aabb) bigorder-是否高位在前 false低位在前
func IPInt642Bytes ¶
IPInt642Bytes change ip int64 data to string format
func IPInt642String ¶
IPInt642String change ip int64 data to string format
func IPUint2Bytes ¶
IPUint2Bytes change ip int64 data to string format
func IPUint2String ¶
IPUint2String change ip int64 data to string format
func IPv6ToInt32Segments ¶
IPv6ToInt32Segments 将 IPv6 地址字符串转换为 16 字节的表示形式。 每个 16 位段使用低字节在前(little-endian per segment)。 支持缩写 ::、带方括号的形式 [::1] 以及带 zone 的形式 fe80::1%eth0。 返回长度为 16 的 byte 数组,解析失败返回错误。
func Int32SegmentsToIPv6 ¶
Int32SegmentsToIPv6 将 16 字节(每段 2 字节,低字节在前,little-endian per segment)的数据 还原为标准的 IPv6 字符串表示(如 "2001:db8::1")。 输入长度必须为 16,否则返回错误。
func Int642Bytes ¶
Int642Bytes 无符号长整形转换字节数组(8位),bigOrder==true,高位在前
func LeftPadZeros ¶
func ParseNumberRange ¶
ParseNumberRange 解析逗号分隔的数字字符串,支持范围表示法(如"2-8") 输入示例: "1,3,5-9,12" 输出: [1,3,5,6,7,8,9,12]
func RemoveUnvisiable ¶
func SignedInt322Byte
deprecated
func SlicesDifference ¶
SlicesDifference 求差集 slice1-并集
func SplitDateTime ¶
SplitDateTime SplitDateTime
func Stamp2Time ¶
Stamp2Time convert stamp to datetime string
func String2Bytes ¶
String2Bytes convert hex-string to []byte
args: data: 输入字符串 sep: 用于分割字符串的分割字符 return: 字节切片
func StringSlice2Int8 ¶
StringSlice2Int8 convert string Slice 2 int8
func StringToFixedRightPad ¶
StringToFixedRightPad 截断或右侧填充 0x00 到指定字节长度 n
func SwitchStamp ¶
SwitchStamp switch stamp format between unix and c#
func Time2Stampf ¶
Time2Stampf 可根据制定的时间格式和时区转换为当前时区的Unix时间戳
s:时间字符串 fmt:时间格式 year:2006,month:01,day:02 hour:15,minute:04,second:05 tz:0~12,超范围时使用本地时区
func Uint642Bytes ¶
Uint642Bytes 长整形转换字节数组(8位),bigOrder==true,高位在前
func ValidateIPPort ¶
ValidateIPPort 验证输入的 "ip:port" 字符串(支持 IPv4 和 IPv6)。 返回解析出的 ip(不含方括号与 zone)和端口号;解析失败返回 error。 支持格式示例:
1.2.3.4:80 [2001:db8::1]:443 2001:db8::1:443 // 尝试通过最后一个冒号分割 host/port(推荐使用带方括号的 IPv6)
注:IPv6 带 zone 的情况会在验证时去掉 zone(例如 fe80::1%eth0 -> fe80::1)。
func WriteVersionInfo ¶
func WriteVersionInfo(p, v, gv, bd, pl, a string)
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
Types ¶
type DurationOptions ¶
type DurationOptions func(opt *durationOption)
func WithEnglishUnit ¶
func WithEnglishUnit(t bool) DurationOptions
func WithShowSeconds ¶
func WithShowSeconds(t bool) DurationOptions
type FlexibleInt64 ¶
type FlexibleInt64 int64
1. 定义一个兼容类型
func (*FlexibleInt64) Int64 ¶
func (f *FlexibleInt64) Int64() int64
func (*FlexibleInt64) UnmarshalJSON ¶
func (f *FlexibleInt64) UnmarshalJSON(data []byte) error
2. 实现 UnmarshalJSON 接口
type StringSliceSort ¶
type StringSliceSort struct {
OneDimensional []string
TwoDimensional [][]string
Idx int
Order string
}
StringSliceSort 字符串数组排序
func (*StringSliceSort) Len ¶
func (arr *StringSliceSort) Len() int
func (*StringSliceSort) Less ¶
func (arr *StringSliceSort) Less(i, j int) bool
func (*StringSliceSort) Swap ¶
func (arr *StringSliceSort) Swap(i, j int)
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cache : 数据缓存模块,可定时清理过期数据
|
Package cache : 数据缓存模块,可定时清理过期数据 |
|
Package config 类ini的配置文件库,支持注释信息
|
Package config 类ini的配置文件库,支持注释信息 |
|
Package coord 坐标相关功能模块
|
Package coord 坐标相关功能模块 |
|
Package cron scheduled jobs
|
Package cron scheduled jobs |
|
Package crypto 加密解密
|
Package crypto 加密解密 |
|
cmd
command
|
|
|
Package db : 数据库模块,封装了常用方法,可缓存数据,可依据配置自动创建myisam引擎的子表,支持mysql和sqlserver
|
Package db : 数据库模块,封装了常用方法,可缓存数据,可依据配置自动创建myisam引擎的子表,支持mysql和sqlserver |
|
Package email : email emtp发送模块
|
Package email : email emtp发送模块 |
|
Package excel excel功能模块
|
Package excel excel功能模块 |
|
Package games : 搜罗的一些网页小游戏
|
Package games : 搜罗的一些网页小游戏 |
|
Package ginmiddleware 基于gin的web框架封装
|
Package ginmiddleware 基于gin的web框架封装 |
|
Package loopfunc : 用于控制需要持续运行的循环方法,当方法漰溃时会自动重启
|
Package loopfunc : 用于控制需要持续运行的循环方法,当方法漰溃时会自动重启 |
|
Package mapfx 线程安全的字典模块
|
Package mapfx 线程安全的字典模块 |
|
Package mq mqtt 和 rmq 相关功能模块
|
Package mq mqtt 和 rmq 相关功能模块 |
|
Package pathtool some path-related methods
|
Package pathtool some path-related methods |
|
Package proc watch process status
|
Package proc watch process status |
|
test
command
|
|
|
Package queue safety queue
|
Package queue safety queue |
|
Package sunriset 日出日落功能模块
|
Package sunriset 日出日落功能模块 |
|
Package tcpfactory 高可用性的tcp服务
|
Package tcpfactory 高可用性的tcp服务 |