util

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecECBString added in v0.0.20

func AesDecECBString(ciphertext []byte, key []byte) (string, error)

AES-128-ECB 解密函数 pkcs5Padding

func AesDecrypt

func AesDecrypt(decryptStr string, key []byte, iv []byte) (string, error)

aes 解密 aes-128-cbc pkcs5Padding

func AesEncECBString added in v0.0.20

func AesEncECBString(plaintext []byte, key []byte) ([]byte, error)

AES-128-ECB 加密函数 pkcs5Padding

func AesEncrypt

func AesEncrypt(encryptStr string, key []byte, iv []byte) (string, error)

aes 加密 aes-128-cbc pkcs5Padding

func Base64DecodeString added in v0.0.20

func Base64DecodeString(text, tp string) (string, error)

base64 decode

func Base64EncodeString added in v0.0.20

func Base64EncodeString(text []byte, tp string) string

base64 encode

func CheckPhoneNumber

func CheckPhoneNumber(phoneNumber string) bool

检查手机号码格式

func ConnectSftp

func ConnectSftp(user, password, host string, port int) (*sftp.Client, error)

获取一个STFP客户端连接

func ContainUpperLowerNumberSpecial

func ContainUpperLowerNumberSpecial(str string, num int) bool

检查是否包含大小写字母以及数字和特殊字符中的指定位数

func EndPadByte

func EndPadByte(text []byte, pad string, size int) []byte

字符串填充2

func EndPadString

func EndPadString(text, pad string, size int) string

向后补充字符串到指定长度

func FirstNonZero added in v0.0.20

func FirstNonZero[T comparable](values ...T) T

通用函数,返回第一个非零值 类似于js语法 a = b || c || d

func FirstNonZeroByAny added in v0.0.20

func FirstNonZeroByAny(values ...any) any

通用函数,返回第一个非零值 如果都是零值,返回最后一个参数 类似于js语法 a = b || c || d

func FormatAndSortJSON added in v0.0.20

func FormatAndSortJSON(jsonStr string) (string, error)

FormatAndSortJSON 格式化并排序 JSON 字符串

func GetClientIp

func GetClientIp(c *fasthttp.RequestCtx) string

获取客户真实ip

func GetTimeByTimestamp added in v0.0.22

func GetTimeByTimestamp(ts int64) string

格式化时间戳

func GetTimestampByStr added in v0.0.22

func GetTimestampByStr(datetime string) int64

格式化时间

func GlobDir

func GlobDir(dir string, fileList *FileListTmp) error

遍历目录下所有文件

func HasKeyBoardContinuousChar

func HasKeyBoardContinuousChar(pwd string, keyBoardSize int, dictionary string) bool

键盘序检查

func Includes

func Includes[S ~[]E, E comparable](strArr S, subStr E) bool

是否包含某个字符串

func IncludesAny

func IncludesAny(arr []any, s any) bool

inludes interface slices.Contains 不能比较 []any

func InterfaceToJson

func InterfaceToJson(i any) (string, error)

转换成json

func IsDigit added in v0.0.20

func IsDigit(text string) bool

判断字符串是否全为数字

func IsEmpty added in v0.0.12

func IsEmpty(v any) bool

IsEmpty 判断值是否为PHP风格的"empty"

func IsEmpty2 added in v0.0.12

func IsEmpty2(v any) bool

字符串"0"不为空

func IsValidIP added in v0.0.20

func IsValidIP(ip string) bool

检查IP合法性

func IsZero added in v0.0.20

func IsZero[T comparable](v T) bool

是否是零值

func JSFilter added in v0.0.22

func JSFilter[T any](s []T, f func(int, T) bool) []T

定义一个泛型函数 Filter,接收一个切片 arr 和一个判断函数 fn,返回过滤后的新切片

func JSMap added in v0.0.22

func JSMap[T any, R any](s []T, f func(T) R) []R

注意值的引用

func Length added in v0.0.20

func Length(args ...string) int

字符串字符数

func Md5Encode

func Md5Encode(text string) string

md5 加密

func Nanoid

func Nanoid(l int) string

按照规则获取随机字符串2

func NanoidAlphabet

func NanoidAlphabet(l int, alphabets ...string) string

按照规则获取随机字符串

func NanoidAlphabetType

func NanoidAlphabetType(alphabetType string, l int) string

按照规则获取随机字符串3 alphabetType number,upperCase,lowerCase

func PathExists added in v0.0.20

func PathExists(path string) (bool, error)

查看文件是否存在

func SendSftp

func SendSftp(user string, password string, host string, port int, filename string, remoteFilePath string) (int, error)

func Sha256Encode

func Sha256Encode(context string) string

sha256加密

func ShuffleString

func ShuffleString(text string) string

字符串乱序

func SortKeysRecursive added in v0.0.20

func SortKeysRecursive(v interface{}) interface{}

SortKeysRecursive 递归对 map 的 key 排序,并处理嵌套结构

func StartPadString

func StartPadString(text, pad string, size int) string

向前补充字符串到指定长度

func SubStrStr

func SubStrStr(context, str string) string

字符串截取 subString 从字符串最后一次出现的位置开始截取支末尾

func Ternary added in v0.0.20

func Ternary[T any](condition bool, trueVal, falseVal T) T

三元运算法

func TypeConversion

func TypeConversion(value string, ntype string) (reflect.Value, error)

类型转换

func Ucs2Decode added in v0.0.12

func Ucs2Decode(hexStr string, endianness string) (string, error)

UCS2 解码

func Ucs2Encode added in v0.0.12

func Ucs2Encode(str string, endianness string) (string, error)

UCS2 编码

func UniqueByKey added in v0.0.20

func UniqueByKey[T, E comparable](data []map[T]E, key T) []map[T]E

对[]map[string]any进行去重

func UploadFileToSftp

func UploadFileToSftp(sftpClient *sftp.Client, localFilename string, remotePath string) (int, error)

上传文件

func ValidatePhoneNumber

func ValidatePhoneNumber(tel string) bool

验证电话号码

Types

type FileListTmp

type FileListTmp struct {
	DirBase string
	Files   []string
	Childs  []*FileListTmp
}

type SendsReturnType

type SendsReturnType struct {
	File string
	N    int
	Err  error
}

func SendSftps

func SendSftps(user string, password string, host string, port int, filenames []string, remoteFilePath string) ([]SendsReturnType, error)

Jump to

Keyboard shortcuts

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