Documentation ¶
Overview ¶
Package gopsu : 收集,保存的一些常用方法
Index ¶
- Constants
- Variables
- func Base64Imgfile(b, f string) error
- func Base64URLDecode(data string) ([]byte, error)
- func Base64UrlSafeEncode(source []byte) string
- 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 Byte2Int32s(v byte, reverse bool) []int32
- func Byte2SignedInt32(b byte) int32
- func Bytes(s string) []byte
- 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 CacheMarshal(v interface{}) ([]byte, error)
- func CacheUnmarshal(b []byte, v interface{}) error
- 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 CompressData(src []byte, t ArchiveType) []byte
- 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 DecodeString(s string) string
- func DecodeStringOld(s string) string
- func DoZlibCompress(src []byte) []byte
- func DoZlibUnCompress(src []byte) []byte
- func EncodeUTF16BE(s string) []byte
- func EraseSyncMap(m *sync.Map)
- func ExternalIP() string
- func ExternalIPV6() string
- func Float32ToByte(float float32) []byte
- func Float642BcdBytes(v float64, f string) []byte
- func Float642BcdBytesBigOrder(v float64, f string) []byte
- func Float64ToByte(float float64) []byte
- func FormatFileSize(fileSize int64) (size string)
- func FormatFloat64(f float64, p int) float64
- func GPS2DFM(l float64) (int, int, float64)
- func GetAddrFromString(straddr string) ([]int64, error)
- func GetClientTLSConfig(certfile, keyfile, rootca string) (*tls.Config, error)
- func GetExecDir() string
- func GetExecName() string
- func GetExecNameWithoutExt() string
- func GetMD5(text string) string
- func GetRandomASCII(l int64) []byte
- func GetRandomString(l int64, letteronly ...bool) string
- func GetServerTLSConfig(certfile, keyfile, clientca string) (*tls.Config, error)
- func GetTCPPort() (int, error)
- func GetUUID1() string
- func GlobalIPs() ([]string, []string, error)
- func HashData(b []byte, cryptoType byte) string
- 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 Imgfile2Base64(s string) (string, error)
- func Int642Bytes(i int64, bigOrder bool) []byte
- func Int82Bcd(v byte) byte
- func IsExist(p string) bool
- func JSON2PB(js string, pb interface{}) error
- func JoinPathFromHere(path ...string) string
- func LastSlice(s, sep string) string
- func MakeRuntimeDirs(rootpath string) (string, string, string)
- func PB2Json(pb interface{}) []byte
- func PB2String(pb interface{}) string
- func RealIP(v6first bool) string
- func ReverseString(s string) string
- func SMSUnicode(s string) []string
- func STime2Bcd(t int32) []byte
- func SignedBytes2Int64(b []byte) int64
- func SignedInt322Byte(i int32) byte
- 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) string
- 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 String2Int32(s string, t int) int32
- func String2Int64(s string, t int) int64
- func String2Int8(s string, t int) byte
- func String2UInt64(s string, t int) uint64
- func String2Unicode(s string) string
- func StringSlice2Int8(bs []string) 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 UncompressData(src []byte, t ArchiveType, dstlen ...interface{}) []byte
- func VersionInfo(p, v, gv, bd, pl, a string) string
- 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 ArchiveType
- type ArchiveWorker
- type ConfData
- func (c *ConfData) AddOrUpdate(key, value, tip string)
- func (c *ConfData) Clear()
- func (c *ConfData) DelItem(key string)
- func (c *ConfData) FullPath() string
- func (c *ConfData) GetAll() string
- func (c *ConfData) GetItem(key string) (string, error)
- func (c *ConfData) GetItemDefault(key, value string, remark ...string) string
- func (c *ConfData) GetKeys() []string
- func (c *ConfData) Len() int
- func (c *ConfData) Reload() error
- func (c *ConfData) Save() error
- func (c *ConfData) SetFullPath(p string)
- func (c *ConfData) SetItem(key, value, tip string) bool
- func (c *ConfData) UpdateItem(key, value string) bool
- type CryptoWorker
- type SliceFlag
- 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 hh:MM:ss DateOnlyFormat = "2006-01-02" // TimeOnlyFormat yyyy-mm-dd 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" // 日志文件命名格式 )
const ( // CryptoMD5 md5算法 CryptoMD5 = iota // CryptoSHA256 sha256算法 CryptoSHA256 // CryptoSHA512 sha512算法 CryptoSHA512 // CryptoHMACSHA1 hmacsha1摘要算法 CryptoHMACSHA1 // CryptoHMACSHA256 hmacsha256摘要算法 CryptoHMACSHA256 // CryptoAES128CBC aes128cbc算法 CryptoAES128CBC // CryptoAES128CFB aes128cfb算法 CryptoAES128CFB // CryptoAES192CBC aes192cbc算法 CryptoAES192CBC // CryptoAES192CFB aes192cfb算法 CryptoAES192CFB // CryptoAES256CBC aes256cbc算法 CryptoAES256CBC // CryptoAES256CFB aes256cfb算法 CryptoAES256CFB )
Variables ¶
var ( // DefaultLogDir 默认日志文件夹 DefaultLogDir = filepath.Join(GetExecDir(), "..", "log") // DefaultCacheDir 默认缓存文件夹 DefaultCacheDir = filepath.Join(GetExecDir(), "..", "cache") // DefaultConfDir 默认配置文件夹 DefaultConfDir = filepath.Join(GetExecDir(), "..", "conf") )
Functions ¶
func Base64UrlSafeEncode ¶
Base64UrlSafeEncode url safe 编码
func Bytes2Float32 ¶
Bytes2Float32 字节数组转单精度浮点,bigOrder==true,高位在前
func Bytes2Float64 ¶
Bytes2Float64 字节数组转双精度浮点,bigOrder==true,高位在前
func Bytes2String ¶
Bytes2String convert []byte to hex-string
args: data: 输入字节切片 sep: 用于分割字符串的分割字符 return: 字符串
func CacheMarshal ¶
CacheMarshal 将数据进行序列化后压缩,可做数据缓存
func CacheUnmarshal ¶
CacheUnmarshal 将压缩的数据反序列化,参数v必须专递结构地址
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 CompressData ¶
func CompressData(src []byte, t ArchiveType) []byte
CompressData 使用gzip,zlib压缩数据
func Float32ToByte ¶ added in v1.3.5
Float32ToByte 32位浮点转bytes
func Float642BcdBytesBigOrder ¶
Float642BcdBytesBigOrder 浮点转bcd字节数组(大端序)
v:十进制浮点数值 f:格式化的字符串,如"%07.03f","%03.0f"
func Float64ToByte ¶ added in v1.3.5
Float64ToByte 64位浮点转bytes
func FormatFileSize ¶ added in v1.3.3
FormatFileSize 字节的单位转换
func FormatFloat64 ¶ added in v1.3.3
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 GetClientTLSConfig ¶
GetClientTLSConfig 获取https配置
certfile: 双向验证时客户端证书 keyfile: 双向验证时客户端key rootca: 服务端根证书
func GetExecNameWithoutExt ¶ added in v1.3.5
func GetExecNameWithoutExt() string
GetExecNameWithoutExt 获取可执行文件的名称,去除扩展名
func GetRandomString ¶
GetRandomString 生成随机字符串
func GetServerTLSConfig ¶
GetServerTLSConfig 获取https配置
certfile: 服务端证书 keyfile: 服务端key clientca: 双向验证时客户端根证书
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 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 Int642Bytes ¶
Int642Bytes 无符号长整形转换字节数组(8位),bigOrder==true,高位在前
func MakeRuntimeDirs ¶
MakeRuntimeDirs make conf,log,cache dirs Args: rootpath: 输入路径 return: conf,log,cache三个文件夹的完整路径
func SignedBytes2Int64 ¶ added in v1.3.5
SignedBytes2Int64 有符号字节数组转int64,低前
func SlicesDifference ¶
SlicesDifference 求差集 slice1-并集
func SplitDateTime ¶
SplitDateTime SplitDateTime
func Stamp2Time ¶
Stamp2Time convert stamp to datetime string
func String2Byte ¶ added in v1.3.5
String2Byte convert string 2 one byte
args: s: 输入字符串 t: 返回数值进制 Return: byte
func String2Bytes ¶
String2Bytes convert hex-string to []byte
args: data: 输入字符串 sep: 用于分割字符串的分割字符 return: 字节切片
func String2Float32 ¶ added in v1.3.5
String2Float32 convert string 2 float64
func String2UInt64 ¶ added in v1.3.5
String2UInt64 convert string 2 uint64
args: s: 输入字符串 t: 返回数值进制 Return: uint64
func StringSlice2Int8 ¶
StringSlice2Int8 convert string Slice 2 int8
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 UncompressData ¶
func UncompressData(src []byte, t ArchiveType, dstlen ...interface{}) []byte
UncompressData 使用gzip,zlib解压缩数据
func VersionInfo ¶
VersionInfo show something
p: program name v: program version gv: golang version bd: build datetime pl: platform info a: auth name
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 ArchiveType ¶ added in v1.3.3
type ArchiveType byte
ArchiveType 压缩编码类型
var ( // ArchiveZlib zlib压缩/解压缩 ArchiveZlib ArchiveType = 1 // ArchiveGZip gzip压缩/解压缩 ArchiveGZip ArchiveType = 2 //ArchiveSnappy snappy压缩,解压缩 ArchiveSnappy ArchiveType = 3 )
type ArchiveWorker ¶
type ArchiveWorker struct {
// contains filtered or unexported fields
}
ArchiveWorker 压缩管理器,避免重复New
func GetNewArchiveWorker ¶
func GetNewArchiveWorker(archiveType ArchiveType) *ArchiveWorker
GetNewArchiveWorker 获取新的压缩管理器
func (*ArchiveWorker) Uncompress ¶
func (a *ArchiveWorker) Uncompress(src []byte) []byte
Uncompress 解压缩
type ConfData ¶
type ConfData struct {
// contains filtered or unexported fields
}
ConfData 配置文件结构体
func (*ConfData) AddOrUpdate ¶ added in v1.3.5
AddOrUpdate 更新配置项
func (*ConfData) GetItemDefault ¶
GetItemDefault 获取配置项的value
func (*ConfData) SetFullPath ¶ added in v1.3.5
SetFullPath 设置配置文件目录
func (*ConfData) UpdateItem ¶
UpdateItem 更新配置项
type CryptoWorker ¶
type CryptoWorker struct {
// contains filtered or unexported fields
}
CryptoWorker 序列化或加密管理器
func GetNewCryptoWorker ¶
func GetNewCryptoWorker(cryptoType byte) *CryptoWorker
GetNewCryptoWorker 获取新的序列化或加密管理器 md5,sha256,sha512初始化后直接调用hash hmacsha1初始化后需调用SetSignKey设置签名key后调用hash aes加密算法初始化后需调用SetKey设置key和iv后调用Encrypt,Decrypt
func (*CryptoWorker) EncryptNoTail ¶
func (h *CryptoWorker) EncryptNoTail(s string) string
EncryptNoTail 加密,去掉base64尾巴的=符号
func (*CryptoWorker) SetKey ¶
func (h *CryptoWorker) SetKey(key, iv string) error
SetKey 设置aes-key,iv
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 db : 数据库模块,封装了常用方法,可缓存数据,可依据配置自动创建myisam引擎的子表,支持mysql和sqlserver
|
Package db : 数据库模块,封装了常用方法,可缓存数据,可依据配置自动创建myisam引擎的子表,支持mysql和sqlserver |
Package email : email emtp发送模块
|
Package email : email emtp发送模块 |
Package games : 搜罗的一些网页小游戏
|
Package games : 搜罗的一些网页小游戏 |
Package geohash : go版的redis-geo模块,貌似有内存泄露问题,待查找和修正,目前不建议使用
|
Package geohash : go版的redis-geo模块,貌似有内存泄露问题,待查找和修正,目前不建议使用 |
Package json : 使用 github.com/bytedance/sonic 替代 encoding/json,性能更好
|
Package json : 使用 github.com/bytedance/sonic 替代 encoding/json,性能更好 |
Package logger 日志专用写入器,可设置是否自动依据日期以及文件大小滚动日志文件
|
Package logger 日志专用写入器,可设置是否自动依据日期以及文件大小滚动日志文件 |
Package loopfunc : 用于控制需要持续运行的循环方法,当方法漰溃时会自动重启
|
Package loopfunc : 用于控制需要持续运行的循环方法,当方法漰溃时会自动重启 |
Package queue 队列模块 HLQueue: wlst tcp module 定制模块,内部分为高低优先级2个队列,高优先级队列可设置先进先出或先进后出,低优先级队列只能先进先出。
|
Package queue 队列模块 HLQueue: wlst tcp module 定制模块,内部分为高低优先级2个队列,高优先级队列可设置先进先出或先进后出,低优先级队列只能先进先出。 |
Package rate provides a rate limiter.
|
Package rate provides a rate limiter. |