util

package
v0.0.0-...-19a85bd Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseGrpcConns

func CloseGrpcConns()

CloseGrpcConns 程序退出时关闭所有 gRPC 连接

func CreateMD5

func CreateMD5(str string) string

MD5 加密

func Decimal

func Decimal(num float64) float64

大数

func DecryptPassword

func DecryptPassword(encryptedPassword string, privateKeyPath string) (string, error)

func ExtractSuffix2Int

func ExtractSuffix2Int(delayStr string, suffix string) int

去除末尾字符并转数字

func FileExists

func FileExists(path string) bool

func Float642String

func Float642String(f64 float64) string

float64 转字符串

func GenerateId

func GenerateId() int64

雪花算法生成新 ID

func GenerateRandomCode

func GenerateRandomCode(length int) (code string)

生成随机验证码

func GetByHttp

func GetByHttp(url string) (string, error)

GetByHttp 基础GET请求

func GetByHttpWithParams

func GetByHttpWithParams(apiUrl string, headers map[string]string, params map[string]string, timeout time.Duration, proxy *string) (string, error)

GetByHttpWithParams 带请求头、参数和超时的GET请求

func GetByHttpWithParamsBackDoc

func GetByHttpWithParamsBackDoc(apiUrl string, headers map[string]string, params map[string]string, timeout time.Duration, proxy *string) (*goquery.Document, error)

GetByHttpWithParamsBackDoc 带参数的GET请求,返回goquery.Document

func GetDateFormatStr

func GetDateFormatStr(format string, date time.Time) string

格式化时间

func GetDigitNow

func GetDigitNow() int

整形返回时间戳

func GetGrpcClientConn

func GetGrpcClientConn(serviceName string, creds *credentials.TransportCredentials) (newConn *grpc.ClientConn, err error)

GetGrpcClientConn 获取指定服务的 gRPC 连接

func GetIP

func GetIP(c *fiber.Ctx) string

获取 IP

func GetStrNow

func GetStrNow() string

字符串返回时间戳

func In

func In[T comparable](target T, aimList []T) bool

Is T In List

func Int2String

func Int2String(i int) string

int 转字符串

func Int642String

func Int642String(i64 int64) string

int64 转字符串

func IsIP

func IsIP(ip string) (net.IP, error)

判断是否 IP

func IsIPv6LinkLocal

func IsIPv6LinkLocal(ip net.IP) bool

func IsNumber

func IsNumber(str string) bool

判断是否为数字

func MergeAndDeduplicate

func MergeAndDeduplicate(arr1, arr2 []int64) []int64

数组去重

func NewToken

func NewToken(userId string, userName string) (string, error)

iss (issuer): 签发人 exp (expiration time): 过期时间 sub (subject): 主题 aud (audience): 受众 nbf (Not Before): 生效时间 iat (Issued At): 签发时间 jti (JWT ID): 编号

func ParseIPv6ToIPv4

func ParseIPv6ToIPv4(ip string) (string, error)

转换IPv6为IPv4

func ParseToken

func ParseToken(authorization string) (*cm.GFClaims, error)

解密JWT Token

func PostByHttp

func PostByHttp(url, contentType string, params map[string]any) (string, error)

PostByHttp 基础POST请求

func PostByHttpWithParams

func PostByHttpWithParams(apiUrl string, headers map[string]string, params map[string]string, timeout time.Duration, proxy *string) (string, error)

PostByHttpWithParams 带参数的POST请求

func Secret

func Secret() jwt.Keyfunc

JWT 密钥

func String2Float64

func String2Float64(str string) (float64, error)

字符串转float64

func String2Int

func String2Int(numString string) (int, error)

字符串转 int

func String2Int64

func String2Int64(numString string) (int64, error)

字符串转 int64

func StringUnicode2Float64

func StringUnicode2Float64(str string) []float64

字符串Unicode转float64

func UnixToTime

func UnixToTime(num int64) string

转换时间戳为时间

Types

This section is empty.

Jump to

Keyboard shortcuts

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