utils

package
v0.0.0-...-d5480cd Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenExpired     = errors.New("令牌超时")
	ErrTokenNotValidYet = errors.New("令牌尚未生效")
	ErrTokenMalformed   = errors.New("非法令牌")
	ErrTokenInvalid     = errors.New("无处理令牌")
	ErrTokenTypeError   = errors.New("令牌类型转换错误")
)
View Source
var (
	IdVerify               = Rules{"ID": []string{NotEmpty()}}
	ApiVerify              = Rules{"Path": {NotEmpty()}, "Description": {NotEmpty()}, "ApiGroup": {NotEmpty()}, "Method": {NotEmpty()}}
	MenuVerify             = Rules{"Path": {NotEmpty()}, "ParentId": {NotEmpty()}, "Name": {NotEmpty()}, "Component": {NotEmpty()}, "Sort": {Ge("0")}}
	MenuMetaVerify         = Rules{"Title": {NotEmpty()}}
	LoginVerify            = Rules{"Secret": {NotEmpty()}}
	RegisterVerify         = Rules{"Username": {NotEmpty()}, "NickName": {NotEmpty()}, "Password": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
	PageInfoVerify         = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
	CustomerVerify         = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
	AutoCodeVerify         = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
	AutoPackageVerify      = Rules{"PackageName": {NotEmpty()}}
	AuthorityVerify        = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}}
	AuthorityIdVerify      = Rules{"AuthorityId": {NotEmpty()}}
	OldAuthorityVerify     = Rules{"OldAuthorityId": {NotEmpty()}}
	ChangePasswordVerify   = Rules{"Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
	SetUserAuthorityVerify = Rules{"AuthorityId": {NotEmpty()}}
)
View Source
var CustomizeMap = make(map[string]Rules)

Functions

func ArrayToString

func ArrayToString(array []interface{}) string

func BcryptCheck

func BcryptCheck(password, hash string) bool

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

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func Contains

func Contains[T comparable](slice []T, item T) bool

切片(/数组)包含方法

func CreateDir

func CreateDir(dirs ...string) (err error)

func DeLFile

func DeLFile(filePath string) error

func Eq

func Eq(mark string) string

func FileExist

func FileExist(path string) bool

FileExist 判断文件是否存在

func FileMove

func FileMove(src string, dst string) (err error)

func FirstLower

func FirstLower(s string) string

func FirstUpper

func FirstUpper(s string) string

func Ge

func Ge(mark string) string

func GetStringWithTime

func GetStringWithTime(src string) string

func Gt

func Gt(mark string) string

func IsValidPassword

func IsValidPassword(password string) bool

检查密码是否满足条件

func Le

func Le(mark string) string

func Lt

func Lt(mark string) string

func MD5V

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

func MaheHump

func MaheHump(s string) string

MaheHump 将字符串转换为驼峰命名

func Ne

func Ne(mark string) string

func NewSnowflakeWorker

func NewSnowflakeWorker(workerId int64) *worker

func NotEmpty

func NotEmpty() string

func ParseDuration

func ParseDuration(d string) (time.Duration, error)

func PathExists

func PathExists(path string) (bool, error)

func Pointer

func Pointer[T any](in T) (out *T)

func RandomInt

func RandomInt(min, max int) int

func RandomString

func RandomString(n int) string

随机字符串

func RegexpMatch

func RegexpMatch(rule string) string

func RegisterRule

func RegisterRule(key string, rule Rules) (err error)

func StructToMap

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

func TrimSpace

func TrimSpace(target interface{})

func Verify

func Verify(st interface{}, roleMap Rules) (err error)

Types

type BaseClaims

type BaseClaims struct {
	ID           uint
	Username     string
	LogOperation bool
	Groups       []string
	Roles        []string
}

type CustomClaims

type CustomClaims struct {
	BaseClaims
	BufferTime int64
	jwt.RegisteredClaims
}

type JWT

type JWT struct {
	SigningKey        []byte
	SingleflightGroup *singleflight.Group
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(baseClaims BaseClaims) CustomClaims

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims CustomClaims) (string, error)

创建一个token

func (*JWT) CreateTokenByOldToken

func (j *JWT) CreateTokenByOldToken(oldToken string, claims CustomClaims) (string, error)

根据旧token创建新token

func (*JWT) ParseToken

func (j *JWT) ParseToken(token string) (*CustomClaims, error)

解析token

type Rules

type Rules map[string][]string

type RulesMap

type RulesMap map[string]Rules

Directories

Path Synopsis
redis
jwt

Jump to

Keyboard shortcuts

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