utils

package
v0.0.0-...-1dec894 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculatePoints

func CalculatePoints(amount int64, ratio float64) int64

CalculatePoints 计算消费积分 amount: 消费金额(分) ratio: 积分比例(每元返多少积分)

func CheckPassword

func CheckPassword(password, hash string) bool

CheckPassword 验证密码

func Deref

func Deref[T any](v *T) T

Deref 解引用指针,如果为nil则返回零值

func GenerateCouponCode

func GenerateCouponCode() string

GenerateCouponCode 生成优惠券码

func GenerateOrderNo

func GenerateOrderNo(prefix string) string

GenerateOrderNo 生成订单号

func GenerateToken

func GenerateToken(userID int64, userType string, storeID int64, roleCode string) (string, error)

GenerateToken 生成JWT token

func GenerateUUID

func GenerateUUID() string

GenerateUUID 生成UUID

func GetEndOfDay

func GetEndOfDay(t time.Time) time.Time

GetEndOfDay 获取当天结束时间

func GetStartOfDay

func GetStartOfDay(t time.Time) time.Time

GetStartOfDay 获取当天开始时间

func HashPassword

func HashPassword(password string) (string, error)

HashPassword 使用 bcrypt 加密密码

func InArray

func InArray[T comparable](item T, array []T) bool

InArray 判断元素是否在数组中

func MD5

func MD5(str string) string

MD5 计算MD5哈希

func Max

func Max[T int | int64 | float64](a, b T) T

Max 返回最大值

func Min

func Min[T int | int64 | float64](a, b T) T

Min 返回最小值

func Pointer

func Pointer[T any](v T) *T

Pointer 返回值的指针

func RandomInt

func RandomInt(max int) int

RandomInt 生成随机整数 [0, max]

func RandomString

func RandomString(length int) string

RandomString 生成随机字符串

func RefreshToken

func RefreshToken(tokenString string) (string, error)

RefreshToken 刷新token

Types

type Claims

type Claims struct {
	UserID   int64  `json:"user_id"`
	UserType string `json:"user_type"`           // member, admin
	StoreID  int64  `json:"store_id,omitempty"`  // 店铺管理员的店铺ID
	RoleCode string `json:"role_code,omitempty"` // 角色代码
	jwt.RegisteredClaims
}

Claims JWT载荷

func ParseToken

func ParseToken(tokenString string) (*Claims, error)

ParseToken 解析JWT token

Jump to

Keyboard shortcuts

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