utils

package
v0.0.0-...-68aaea9 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Aes = &xAes{}
View Source
var Bytes = &xBytes{}
View Source
var DecryptError = errors.New("aes decrypt error")
View Source
var Error = &xError{}
View Source
var File = &xFile{}
View Source
var Http = &xHttp{}
View Source
var Json = &xJson{}
View Source
var Map = &xMap{}
View Source
var Number = &xNumber{}
View Source
var Pwd = &xPwd{}
View Source
var Random = &xRandom{}
View Source
var Regex = &xRegex{}
View Source
var Retry = xRetry{}
View Source
var SetTokenLockError = fmt.Errorf("set token lock error")
View Source
var Snowflake *xSnowflake
View Source
var String = &xString{}
View Source
var Time = &xTime{}
View Source
var TokenExpiredError = fmt.Errorf("token expired error")
View Source
var TokenInvalidError = fmt.Errorf("token invalid error")
View Source
var TokenReplaceError = fmt.Errorf("token replace error")
View Source
var Trace = &xTrace{}

Functions

func AnyInSlice

func AnyInSlice[T AnyInSliceType](v T, slice []T) bool

func AnyPtr

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

func AnySet

func AnySet[T AnyInSliceType](list []T) []T

func AnyString

func AnyString(o any) string

func EnumInSlice

func EnumInSlice[T EnumInSliceType](v T, slice []T) bool

func GetPodIp

func GetPodIp() string

func Md5

func Md5(s string) string

func Md516

func Md516(s string) string

func Md5Bytes

func Md5Bytes(b []byte) string

Types

type AnyInSliceType

type AnyInSliceType interface {
	string | int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | float32 | float64 | bool
}

type EnumInSliceType

type EnumInSliceType interface {
	String() string
}

type Jwt

type Jwt struct {
	Config JwtConfig
	// contains filtered or unexported fields
}

func NewJwt

func NewJwt(
	config JwtConfig,
	rc *redis.Redis,
) *Jwt

func (*Jwt) GenerateToken

func (x *Jwt) GenerateToken(
	userId string,
	uniqueKey string,
	status int,
	extra string,
	scope []string,
) *TokenObject

func (*Jwt) RevokeToken

func (x *Jwt) RevokeToken(
	ctx context.Context,
	userId string,
	uniqueKey string,
) error

func (*Jwt) SetToken

func (x *Jwt) SetToken(
	ctx context.Context,
	tokenObject *TokenObject,
) error

func (*Jwt) VerifyToken

func (x *Jwt) VerifyToken(
	ctx context.Context,
	tokenString string,
	uniqueKey string,
) (*TokenObject, error)

type JwtConfig

type JwtConfig struct {
	PrivateKey string
	ExpireHour int    `json:",default=24"`
	MaxToken   int    `json:",default=5"`    // 每一个key 最大token数量
	Scene      string `json:",default=user"` // user,admin,other
}

type SSM

type SSM map[string]string

func NewSSMFromBsonM

func NewSSMFromBsonM(m bson.M) SSM

func (SSM) Get

func (ssm SSM) Get(k string) string

func (SSM) GetInt64

func (ssm SSM) GetInt64(k string) int64

func (SSM) GetOrDefault

func (ssm SSM) GetOrDefault(k string, def string) string

func (SSM) Marshal

func (ssm SSM) Marshal() string

func (SSM) ToSA

func (ssm SSM) ToSA() map[string]any

func (SSM) ToSS

func (ssm SSM) ToSS() map[string]string

type TokenObject

type TokenObject struct {
	UserId    string   `json:"userId"`    // 用户id
	UniqueKey string   `json:"uniqueKey"` // 唯一标识 比如设备id/平台id 就可以实现单点登录/单平台登录/任意登录
	Status    int      `json:"status"`    // 状态 用户自行定义
	Token     string   `json:"token"`     // token
	Extra     string   `json:"extra"`     // 额外信息 用户自行定义
	AliveTime int64    `json:"aliveTime"` // 存活时间
	ExpiredAt int64    `json:"expiredAt"` // 过期时间
	Scope     []string `json:"scope"`     // 权限
	Scene     string   `json:"scene"`     // 场景
}

func (*TokenObject) Marshal

func (o *TokenObject) Marshal() string

Jump to

Keyboard shortcuts

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