utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

file: url_match.go Package urlmatch 提供与 Gin 路由语义一致的 URL 匹配工具(对称匹配)

Index

Constants

View Source
const (
	Black  = "Black"
	White  = "White"
	Red    = "Red"
	Blue   = "Blue"
	Yellow = "Yellow"
	Green  = "Green"
)
View Source
const Print = 0
View Source
const PrintLn = 1

Variables

This section is empty.

Functions

func BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func Cc2Udl

func Cc2Udl(str string) string

Cc2Udl 大,小驼峰转下划线

func Eval

func Eval(str string) (evalVal string)

string list to list

func FillToLen

func FillToLen(str string, length int) string

将字符串填充到指定位数

func FillToLenByChar

func FillToLenByChar(str string, length int, char string) string

func FirstLower

func FirstLower(s string) string

FirstLower 字符串首字母小写

func FirstUpper

func FirstUpper(s string) string

FirstUpper 字符串首字母大写

func GenLicense

func GenLicense(privateKeyStr string, payload LicensePayload) ([]byte, error)

func GenRSAKeyPair

func GenRSAKeyPair(bits int) (privateKeyPEM string, publicKeyPEM string, err error)

GenRSAKeyPair 生成 RSA 公私钥(PEM 格式字符串)。 私钥使用 PKCS8 编码,公钥使用 PKIX 编码,和当前签名/验签逻辑保持一致。

func GetInstance

func GetInstance() *idGenerator

func HexToBigInt

func HexToBigInt(hex string) *big.Int

16进制字符串转BigInt

func HexToInt64

func HexToInt64(hex string) int64

16进制字符串转int64

func HidStr

func HidStr(str string, prefixLen int, suffixLen int) string

隐藏字符串以*代替 包含fromIndex,但是不包含toIndex 和 slice的规则一致

func InitSnowFlakeWorker

func InitSnowFlakeWorker(workerID, dataCenterID int64) error

func Int64ToStr

func Int64ToStr(num int64) string

int64到字符串

func IntToStr

func IntToStr(num int) string

int到字符串

func InterfaceToBigInt

func InterfaceToBigInt(v interface{}) *big.Int

转big.int

func InterfaceToByte

func InterfaceToByte(v interface{}) []byte

任意类型转字符串

func InterfaceToDecimal

func InterfaceToDecimal(v interface{}) decimal.Decimal

func InterfaceToFloat32

func InterfaceToFloat32(v interface{}) float32

转float64

func InterfaceToFloat64

func InterfaceToFloat64(v interface{}) float64

func InterfaceToInt

func InterfaceToInt(v interface{}) int

func InterfaceToInt8

func InterfaceToInt8(v interface{}) int8

func InterfaceToInt16

func InterfaceToInt16(v interface{}) int16

func InterfaceToInt32

func InterfaceToInt32(v interface{}) int32

func InterfaceToInt64

func InterfaceToInt64(v interface{}) int64

func InterfaceToStr

func InterfaceToStr(v interface{}) string

任意类型转字符串

func InterfaceToUInt

func InterfaceToUInt(v interface{}) uint

func InterfaceToUInt8

func InterfaceToUInt8(v interface{}) uint8

func InterfaceToUInt16

func InterfaceToUInt16(v interface{}) uint16

func InterfaceToUInt32

func InterfaceToUInt32(v interface{}) uint32

func InterfaceToUInt64

func InterfaceToUInt64(v interface{}) uint64

func MD5V

func MD5V(str []byte, b ...byte) string

func MapToStruct

func MapToStruct(mapValue interface{}, structValue interface{}) (err error)

将map转为struct

func PrintBlack

func PrintBlack(content ...interface{})

PrintBlack 行内打印,黑色

func PrintBlue

func PrintBlue(content ...interface{})

PrintBlue 行内打印,蓝色

func PrintGreen

func PrintGreen(content ...interface{})

PrintGreen 行内打印,绿色

func PrintLnBlack

func PrintLnBlack(content ...interface{})

PrintLnBlack 行打印,黑色

func PrintLnBlue

func PrintLnBlue(content ...interface{})

PrintLnBlue 行打印,蓝色

func PrintLnGreen

func PrintLnGreen(content ...interface{})

PrintLnGreen 行打印,绿色

func PrintLnRed

func PrintLnRed(content ...interface{})

PrintLnRed 行打印,红色

func PrintLnWhite

func PrintLnWhite(content ...interface{})

PrintLnWhite 行打印,白色

func PrintLnYellow

func PrintLnYellow(content ...interface{})

PrintLnYellow 行打印,黄色

func PrintRed

func PrintRed(content ...interface{})

PrintRed 行内打印,红色

func PrintWhite

func PrintWhite(content ...interface{})

PrintWhite 行内打印,白色

func PrintYellow

func PrintYellow(content ...interface{})

PrintYellow 行内打印,黄色

func RandomHexStr

func RandomHexStr(len int) (str string)

产生指定长度的16进制字符串

func RandomNumStr

func RandomNumStr(len int) (randomNum string)

产生指定长度的数字随机数

func ReFormatMoney

func ReFormatMoney(str string) string

ReFormatMoney 格式化金额 格式化规则: 从右边开始按照每3个长度切割字符串并使用 `,` 拼接 e.g: input:12000 -> output:12,000 ; input:1200000 -> output:1,200,000

func SnowFlakeNextID

func SnowFlakeNextID() (int64, error)

* 通过雪花算法获取id @return int64 生成的id @return error 返回的错误

func StrFilterChinese

func StrFilterChinese(src string) string

去除字符串中的中文字符

func StrFilterNum

func StrFilterNum(src string) string

提取字符串中的数字 支持提取 浮点数

func StrIsNumber

func StrIsNumber(str string) bool

StrIsNumber 判断字符串是否纯数字

func StrToInt

func StrToInt(num string) int

字符串转int

func StrToInt8

func StrToInt8(num string) int8

字符串转int32

func StrToInt16

func StrToInt16(num string) int16

func StrToInt32

func StrToInt32(num string) int32

func StrToInt64

func StrToInt64(num string) int64

字符串转int64

func StrToUInt

func StrToUInt(num string) uint

TODO -12 不能转到 12

func StrToUInt8

func StrToUInt8(num string) uint8

func StrToUInt16

func StrToUInt16(num string) uint16

func StrToUInt32

func StrToUInt32(num string) uint32

func StrToUInt64

func StrToUInt64(num string) uint64

func StructToMap

func StructToMap(obj interface{}) (data map[string]interface{})

* struct 转 map

func TrimSpace

func TrimSpace(objJsonStr string) string

func Udl2LCC

func Udl2LCC(s string) (camelCase string)

Udl2LCC 下划线转小驼峰 underline to lower camel case

func Udl2UCC

func Udl2UCC(s string) (camelCase string)

Udl2UCC 下划线转大驼峰 underline to upper camel case

func UnderscoreToCamel

func UnderscoreToCamel(name string) string

下划线转大驼峰

func Unique

func Unique[T unique](t []T) []T

func UrlIsEq

func UrlIsEq(source, target string) bool

UrlIsEq 判断两个 URL / 路由定义是否等价

支持:

  • 固定路径 /api/v1/users
  • 参数路径 /api/v1/users/:id
  • Gin 通配路径 /api/v1/users/*path
  • 忽略 query ?a=1

source / target 顺序无关

Types

type Color

type Color string

type ConsoleColorLog

type ConsoleColorLog struct {
}

func (ConsoleColorLog) Debug

func (c ConsoleColorLog) Debug(args ...interface{})

func (ConsoleColorLog) Error

func (c ConsoleColorLog) Error(args ...interface{})

func (ConsoleColorLog) Info

func (c ConsoleColorLog) Info(args ...interface{})

func (ConsoleColorLog) Panic

func (c ConsoleColorLog) Panic(args ...interface{})

func (ConsoleColorLog) Warn

func (c ConsoleColorLog) Warn(args ...interface{})

type LicensePayload

type LicensePayload struct {
	Version   string    `json:"version"`
	LicenseID string    `json:"licenseID"`
	Customer  string    `json:"customer"`
	Product   string    `json:"product"`
	NotBefore time.Time `json:"notBefore"`
	NotAfter  time.Time `json:"notAfter"`
	Features  []string  `json:"features"`
}

func VerifyLicense

func VerifyLicense(publicKeyStr string, licenseFile string) (bool, *LicensePayload)

type SignedLicense

type SignedLicense struct {
	Payload   LicensePayload `json:"payload"`
	Signature string         `json:"signature"` // base64
}

type Worker

type Worker struct {
	LastStamp    int64 // 记录上一次ID的时间戳
	WorkerID     int64 // 该节点的ID
	DataCenterID int64 // 该节点的 数据中心ID
	Sequence     int64 // 当前毫秒已经生成的ID序列号(从0 开始累加) 1毫秒内最多生成4096个ID
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(workerID, dataCenterID int64) *Worker

分布式情况下,我们应通过外部配置文件或其他方式为每台机器分配独立的id

func (*Worker) NextID

func (w *Worker) NextID() (int64, error)

* 具体的雪花算法实现 @return int64 生成的id @return error 返回的错误

Source Files

  • cert.go
  • console_color_print.go
  • hash.go
  • slice.go
  • snowflake.go
  • str.go
  • url.go

Directories

Path Synopsis
Package structs contains various utilities functions to work with structs.
Package structs contains various utilities functions to work with structs.

Jump to

Keyboard shortcuts

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