utils

package
v1.1.46 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: GPL-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FilePathExist = IsExistPath

FilePathExist 文件路径是否存在

Functions

func AesDecrypt added in v1.1.46

func AesDecrypt(baseStr string, key []byte) (origData []byte, aesErr error)

AesDecrypt AES解密

func AesEncrypt added in v1.1.46

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

AesEncrypt AES加密,CBC 注意:aes密钥key的长度必须为16,24,32个字符

func Base64Decode added in v1.1.10

func Base64Decode(s string) string

func Base64Encode added in v1.1.10

func Base64Encode(s string) string

func BasePath

func BasePath() string

BasePath 运行的程序所在目录

func BytesToString added in v1.1.43

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func CBCDecrypt added in v1.1.46

func CBCDecrypt(sign string, key, iv []byte) (string, error)

CBCDecrypt CBC解密

func CBCEncrypt added in v1.1.46

func CBCEncrypt(text string, key []byte, iv []byte) (string, error)

CBCEncrypt CBC加密

func CapturePanic added in v1.1.46

func CapturePanic() (has bool)

func CompareVersion added in v1.1.7

func CompareVersion(ver, cVer string) int

CompareVersion 比较版本,-1:小于,0:相等,1:大于 v1.1.1 compare v1.2.1

func CurrentPath

func CurrentPath() string

CurrentPath 当前目录(与运行程序所在目录无关)

func DecodeBase64 added in v1.1.46

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

DecodeBase64 base64解码处理

func EncodeBase64 added in v1.1.46

func EncodeBase64(b []byte) string

EncodeBase64 base64编码处理

func FileExt added in v1.1.9

func FileExt(file string) string

FileExt 获取文件后缀

func FindStrBetweenStr added in v1.1.45

func FindStrBetweenStr(s string, left, right string) string

FindStrBetweenStr 查找left和right字符串中间的字符串

func FmtPageParams added in v1.1.7

func FmtPageParams(pageNum, pageSize int64) (int64, int64)

func GetLocalIP

func GetLocalIP() (ipv4 string, err error)

获取本机网卡IP

func GetRequestIp added in v1.1.7

func GetRequestIp(r *http.Request) string

returns request real ip.

func InStringArray added in v1.1.9

func InStringArray(s string, arr []string) bool

func Interface2Float64 added in v1.1.43

func Interface2Float64(d interface{}) float64

Interface2Float64 任意值转float64

func Interface2Int64 added in v1.1.19

func Interface2Int64(d interface{}) int64

Interface2Int64 任意值转int64

func InterfaceToArray added in v1.1.46

func InterfaceToArray(records interface{}) []interface{}

InterfaceToArray 转换任意interface{}为数组interface{}

func InterfaceToSqlString added in v1.1.43

func InterfaceToSqlString(a interface{}) string

func IsExistPath added in v1.1.9

func IsExistPath(path string) bool

IsExistPath 文件或目录是否存在

func IsNil added in v1.1.46

func IsNil(t interface{}) bool

IsNil 判断是否是nil

func LoopDo added in v1.1.44

func LoopDo(f func() bool, dur time.Duration) func()

LoopDo 重复执行

func LoopDoI added in v1.1.44

func LoopDoI(f func(int64) bool, dur time.Duration) func()

LoopDoI 重复执行(执行包含序号i)

func MaxInt added in v1.1.46

func MaxInt(a int, b int) int

func MaxInt64 added in v1.1.46

func MaxInt64(a int64, b int64) int64

func Md5Sum added in v1.1.7

func Md5Sum(s string) string

func MinInt added in v1.1.46

func MinInt(a int, b int) int

func MinInt64 added in v1.1.46

func MinInt64(a int64, b int64) int64

func MoreValueChooseFloat64 added in v1.1.46

func MoreValueChooseFloat64(value float64, more ...float64) float64

MoreValueChooseFloat64 多个值选择string,若没有more则默认value,有more则选择more的第一个

func MoreValueChooseInt64 added in v1.1.46

func MoreValueChooseInt64(value int64, more ...int64) int64

MoreValueChooseInt64 多个值选择int64,若没有more则默认value,有more则选择more的第一个

func MoreValueChooseString added in v1.1.46

func MoreValueChooseString(value string, more ...string) string

MoreValueChooseString 多个值选择string,若没有more则默认value,有more则选择more的第一个

func NewMd5Password added in v1.1.7

func NewMd5Password(password string, secret string) string

func NewRequestId

func NewRequestId() string

func NewTrueScopeRand added in v1.1.46

func NewTrueScopeRand() *mrand.Rand

func PKCS7Padding added in v1.1.46

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

PKCS7Padding 填充加密块

func PKCS7UnPadding added in v1.1.46

func PKCS7UnPadding(origData []byte) []byte

PKCS7UnPadding 清除加密块中填充字节

func PadLeftString added in v1.1.46

func PadLeftString(str string, l int, pad string) string

PadLeftString 左填充字符串至指定长度

func PadRightString added in v1.1.46

func PadRightString(str string, l int, pad string) string

PadRightString 右填充字符串至指定长度

func RandCode added in v1.1.8

func RandCode(l int, chars []string) string

func RandFigureCode added in v1.1.8

func RandFigureCode(l int) string

func RandLetterCode added in v1.1.8

func RandLetterCode(l int) string

func RandLetterFigureCode added in v1.1.8

func RandLetterFigureCode(l int) string

func RandNickname added in v1.1.46

func RandNickname() string

RandNickname 随机昵称

func RandOrderNoByDateTime added in v1.1.46

func RandOrderNoByDateTime(prefix string, useDate bool, useTime bool, randLen int) string

RandOrderNoByDateTime 按日期生成单据编号,类似: TX202404230714209992

func ReadYaml added in v1.1.7

func ReadYaml(data interface{}, yamlContent string) error

func ReadYamlFile added in v1.1.7

func ReadYamlFile(data interface{}, configPath string) error

func ScanDirFileDo added in v1.1.46

func ScanDirFileDo(dir string, fn func(file string, path string) error) error

ScanDirFileDo 扫描目录文件并执行操作

func ScanEmbedFsDo added in v1.1.43

func ScanEmbedFsDo(embFs embed.FS, fn func(file string, path string) error) error

ScanEmbedFsDo 扫描文件操作 注意:下划线文件不会被 embed.FS 嵌入打包进来

func ScopeCreateSQLv1916 added in v1.1.43

func ScopeCreateSQLv1916(scope *gorm.Scope)

ScopeCreateSQLv1916 使用gorm scope生成create sql和vars(适用于gorm v1.9.16版本) copy from gorm source code scope.SQL, scope.SQLVars

func ScopeUpdateSQLv1916 added in v1.1.44

func ScopeUpdateSQLv1916(scope *gorm.Scope)

ScopeUpdateSQLv1916 使用gorm scope生成update sql和vars(适用于gorm v1.9.16版本) copy from gorm source code scope.SQL, scope.SQLVars

func Signature added in v1.1.46

func Signature(params ...string) string

Signature 签名

func SliceInt64ToMap added in v1.1.44

func SliceInt64ToMap(src []int64) map[int64]bool

SliceInt64ToMap 切片转map(去重)

func StringToBytes added in v1.1.43

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice without a memory allocation.

func TrueScopeRand added in v1.1.45

func TrueScopeRand(min int64, max int64) int64

TrueScopeRand 真随机数,范围随机,min<= V <max

func TrueScopeRandNoSafe added in v1.1.46

func TrueScopeRandNoSafe(min int64, max int64) int64

TrueScopeRandNoSafe 真随机数(非并发安全) 全局使用一个rand的情况下会引发数组panic(未知原因)

Types

type BatchPointCostPrinter added in v1.1.45

type BatchPointCostPrinter struct {
	log.InvokeLog
	// contains filtered or unexported fields
}

BatchPointCostPrinter 批量点位耗时打印

func NewBatchPointCostPrinter added in v1.1.45

func NewBatchPointCostPrinter() *BatchPointCostPrinter

func (*BatchPointCostPrinter) AddPoint added in v1.1.45

func (printer *BatchPointCostPrinter) AddPoint(name string)

func (*BatchPointCostPrinter) Print added in v1.1.45

func (printer *BatchPointCostPrinter) Print(id string, ts ...*CostPoint)

type CostPoint added in v1.1.45

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

CostPoint 耗时点位信息

func NewCostPoint added in v1.1.45

func NewCostPoint(name string, ts ...time.Time) *CostPoint

Jump to

Keyboard shortcuts

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