putil

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIDMgr = NewIDManager(100000)

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

func AesDecryptFromBase64

func AesDecryptFromBase64(b64 string, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

func AesEncryptToBase64

func AesEncryptToBase64(origData, key []byte) (string, error)

func BoolToStr

func BoolToStr(value bool) string

BoolToStr converts bool to string.

func ByteToStr

func ByteToStr(value byte) string

ByteToStr converts byte to string.

func Bytes2Length

func Bytes2Length(ret []byte) int64

Bytes2Length converts a byte array to an int64 value.

func Crc32

func Crc32(src string) (string, error)

Crc32 returns file's crc32 string.

func DecodeBase64

func DecodeBase64(input string) ([]byte, error)

DecodeBase64 decode a base64 string.

func DecodeBase64Str

func DecodeBase64Str(input string) string

DecodeBase64Str decode a base64 string.

func DecodeHex

func DecodeHex(input string) ([]byte, error)

func EncodeBase64

func EncodeBase64(input string) string

-------------------------------------------------- EncodeBase64 converts an input string to base64 string.

func EncodeHex

func EncodeHex(input []byte) string

--------------------------------------------------

func FillPrefixToLen

func FillPrefixToLen(in, prefix string, length int) string

func Float32ToStr

func Float32ToStr(value float32) string

Float32ToStr converts float32 to string.

func Float32ToStrPrec2

func Float32ToStrPrec2(value float32) string

Float32ToStr converts float32 to string. Keep prec of 2

func Float64ToStr

func Float64ToStr(value float64) string

Float64ToStr converts float64 to string.

func Float64ToStrByPrec

func Float64ToStrByPrec(f float64, prec int) string

func Float64ToStrPrec2

func Float64ToStrPrec2(f float64) string

Float64ToStr converts float64 to string. Keep prec of 2

func GetCallerFuncName

func GetCallerFuncName(skip int) string

func GetCurDir

func GetCurDir() string

os.Getwd() 获取当前工作目录

func GetExecFolder

func GetExecFolder() string

获取当前程序/可执行文件,所在的文件夹,的绝对路径

func GetExecName

func GetExecName() (n string)

func GetExecPath

func GetExecPath() string

获取当前程序/可执行文件,所在的绝对路径

func GetFileMd5

func GetFileMd5(fi string) (string, error)

GetFileMd5 gets file's md5.

func GetFileMd5Stream

func GetFileMd5Stream(f io.Reader) (string, error)

GetFileMd5Stream gets file's md5 by io.Reader

func GetFuncName

func GetFuncName(i any) string

func GetRand

func GetRand(start, end int) int

[start, end)

func GetRandStr

func GetRandStr(n int) string

func GetSha256

func GetSha256(data []byte) string

func GetUrlQueryString added in v0.0.5

func GetUrlQueryString(req any) (querys map[string]string)

func HmacSha256

func HmacSha256(data, secret string) []byte

--------------------------------------------------

func HttpDo

func HttpDo(req *http.Request) (bodyBytes []byte, err error)

func Int8ToStr

func Int8ToStr(value int8) string

Int8ToStr converts int32 to string.

func Int16ToStr

func Int16ToStr(value int16) string

Int16ToStr converts int32 to string.

func Int32ListExcept

func Int32ListExcept(baseList []int32, exclude []int32) (ret []int32)

差集:输出,baseList中有,exclude中没有,的元素

func Int32ListIntersect

func Int32ListIntersect(nums1 []int32, nums2 []int32) []int32

int32数组交集,输出排序是根据nums2的排序

func Int32ListToStr

func Int32ListToStr(Int32List []int32, split string) string

-------------------------------------------------- Int32ListToStr []int32 to string

func Int32ListToStrWithDelimiter

func Int32ListToStrWithDelimiter(Int32List []int32, split, left, right string) string

--------------------------------------------------

func Int32ListUnion

func Int32ListUnion(nums1 []int32, nums2 []int32) []int32

Int32ListUnion int32数组并集,去除重复数据

func Int32ListUnique

func Int32ListUnique(list []int32) []int32

Int32ListUnique int32数组去重

func Int32ToStr

func Int32ToStr(value int32) string

Int32ToStr converts int32 to string.

func Int64ToStr

func Int64ToStr(value int64) string

Int64ToStr converts int64 to string.

func IntToStr

func IntToStr(value int) string

IntToStr converts int to string.

func InterfaceToInt32

func InterfaceToInt32(val any, defaultVal int32) int32

--------------------------------------------------

func InterfaceToString

func InterfaceToString(val any, defaultVal string) string

func IsFuncParamPB added in v0.0.5

func IsFuncParamPB(f any) bool

--------------------------------------------------

func IsPB added in v0.0.5

func IsPB(t reflect.Type) bool

func Length2Bytes

func Length2Bytes(len int64, buffer []byte) []byte

-------------------------------------------------- Length2Bytes converts an int64 value to a byte array.

func Md5Sum

func Md5Sum(input ...string) string

-------------------------------------------------- Md5Sum calculates md5 value of some strings.

func MessageToCleanString added in v0.0.5

func MessageToCleanString(msg proto.Message, str *string) error

func MessageToString added in v0.0.5

func MessageToString(msg proto.Message, str *string) error

func NewHttpRequest

func NewHttpRequest(method, rawURL string, header, querys map[string]string, body string) (*http.Request, error)

func NewHttpRequestJson

func NewHttpRequestJson(method, rawURL string, header, querys map[string]string, body any) (*http.Request, error)

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func ReplaceByStringMap

func ReplaceByStringMap(str string, replaceMap map[string]string) string

根据替换映射表替换字符串,要注意map的数据,不要造成循环替换

func RsaDecryptFromBase64

func RsaDecryptFromBase64(priKey *rsa.PrivateKey, encryptedMsg64 string) string

func RsaEncryptToBase64

func RsaEncryptToBase64(pubKey *rsa.PublicKey, msg string) string

func RsaGetPriKey

func RsaGetPriKey(priKeyBytes []byte) *rsa.PrivateKey

func RsaGetPubKey

func RsaGetPubKey(pubKeyBytes []byte) *rsa.PublicKey

func StrFirstToLower

func StrFirstToLower(str string) string

func StrFirstToUpper

func StrFirstToUpper(str string) string

func StrIdToLower

func StrIdToLower(str string) string

gorm-gen 工具生成的字段采用ID命名 protoc 工具生成的字段采用Id命名 使用起来依然太复杂,简单的代码替换难以分析是orm代码还是pb代码,干脆proto用ID命名就行了 本次代码提交,先保留调用,实现为空

func StrListExcept

func StrListExcept(baseList []string, exclude []string) (ret []string)

差集:输出,baseList中有,exclude中没有,的元素

func StrListToStr

func StrListToStr(stringList []string, split string) string

-------------------------------------------------- StringListToStr []string to string

func StrListUnion

func StrListUnion(list1 []string, list2 []string) []string

StrListUnion string数组并集,去除重复数据

func StrListUnique

func StrListUnique(list []string) []string

StrListUnique string数组去重

func StrListXOR

func StrListXOR(a []string, b []string) (ret []string)

取名XOR异或,实际逻辑是(A-B)U(B-A)的集合b https://www.lodashjs.com/docs/lodash.xor

func StrToBool

func StrToBool(value string) (bool, error)

StrToBool converts string to bool.

func StrToByte

func StrToByte(value string) (byte, error)

StrToByte converts string to byte.

func StrToCamelCase

func StrToCamelCase(str string) string

func StrToFloat32

func StrToFloat32(value string) (float32, error)

StrToFloat32 converts string to float32.

func StrToFloat64

func StrToFloat64(value string) (float64, error)

StrToFloat64 converts string to float64.

func StrToFloat64WithDefault

func StrToFloat64WithDefault(value string, d float64) float64

StrToFloat64 converts string to float64.

func StrToInt

func StrToInt(value string) (int, error)

StrToInt converts string to int.

func StrToInt8

func StrToInt8(value string) (int8, error)

StrToInt8 converts string to int8.

func StrToInt16

func StrToInt16(value string) (int16, error)

StrToInt16 converts string to int16.

func StrToInt32

func StrToInt32(value string) (int32, error)

StrToInt32 converts string to int32.

func StrToInt32List

func StrToInt32List(str string, split string) (ret []int32, err error)

StrToInt32List string to []int32

func StrToInt32List2

func StrToInt32List2(str, start, end, split string) ([]int32, error)

func StrToInt32ListWithDelimiter

func StrToInt32ListWithDelimiter(str, split, left, right string) (ret []int32, err error)

StrToInt32List string to []int32

func StrToInt32WithDefault

func StrToInt32WithDefault(value string, defaultVal int32) int32

StrToInt32 converts string to int32.

func StrToInt64

func StrToInt64(value string) (int64, error)

StrToInt64 converts string to int64.

func StrToInt64WithDefault

func StrToInt64WithDefault(value string, defaultVal int64) int64

StrToInt64 converts string to int64.

func StrToStrList

func StrToStrList(str string, split string) (ret []string)

StrToStringList string to []string, ignore empty string item

func StrToStrListByStartAndEnd

func StrToStrListByStartAndEnd(s string, splitStart string, splitEnd string) (ret []string)

func StrToStrListWithEmpty

func StrToStrListWithEmpty(str string, split string) (ret []string)

StrToStringList string to []string, include empty string item

func StrToStrListWithSplit

func StrToStrListWithSplit(str string, split string) (ret []string)

StrToStrList基础上,分割后不删除split字符

func StrToUint

func StrToUint(value string) (uint, error)

StrToInt converts string to int.

func StrToUint8

func StrToUint8(value string) (uint8, error)

StrToUint8 converts string to uint8.

func StrToUint16

func StrToUint16(value string) (uint16, error)

StrToUint16 converts string to int16.

func StrToUint32

func StrToUint32(value string) (uint32, error)

StrToUint32 converts string to uint32.

func StrToUint64

func StrToUint64(value string) (uint64, error)

StrToUint64 converts string to uint64.

func StrToUpperCamelCase

func StrToUpperCamelCase(s string) string

func StringToMessage added in v0.0.5

func StringToMessage(str *string, msg proto.Message) error

--------------------------------------------------

func TimeFromStr

func TimeFromStr(timeStr, format string) (time.Time, error)

func TimeFromStrDefault

func TimeFromStrDefault(timeStr string) (time.Time, error)

func TimeToStr

func TimeToStr(t time.Time, format string) string

func TimeToStrDefault

func TimeToStrDefault(t time.Time) string

func UUID added in v0.0.5

func UUID() string

--------------------------------------------------

func UUID_S added in v0.0.5

func UUID_S() string

截断的短版UUID

func Uint8ToStr

func Uint8ToStr(value uint8) string

Uint8ToStr converts int32 to string.

func Uint16ToStr

func Uint16ToStr(value uint16) string

Uint16ToStr converts int32 to string.

func Uint32ToStr

func Uint32ToStr(value uint32) string

Uint32ToStr converts int32 to string.

func Uint64ToStr

func Uint64ToStr(value uint64) string

Uint64ToStr converts uint64 to string.

func UintToStr

func UintToStr(value uint) string

UintToStr converts int to string.

func WalkSliceByStep added in v0.0.5

func WalkSliceByStep(x any, step int, cb func(s, e int) error) (err error)

Types

type IDManager added in v0.0.5

type IDManager struct {
	// contains filtered or unexported fields
}

func NewIDManager added in v0.0.5

func NewIDManager(initMaxId int32) *IDManager

func (*IDManager) GetNewSmallestAndUniqueID added in v0.0.5

func (m *IDManager) GetNewSmallestAndUniqueID() int32

获取最小但不重复的ID

func (*IDManager) ReleaseID added in v0.0.5

func (m *IDManager) ReleaseID(id int32)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL