utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired ")
	TokenNotValidYet = errors.New("Token not active yet ")
	TokenMalformed   = errors.New("That's not even a token ")
	TokenInvalid     = errors.New("Couldn't handle this token: ")
)
View Source
var (
	ConfigEnv  = "APP_CONFIG"
	ConfigFile = "config.yaml"
)

Functions

func SetConfigEnv

func SetConfigEnv(str string)

func SetConfigFile

func SetConfigFile(str string)

Types

type BaseClaims

type BaseClaims struct {
	UUID        uuid.UUID
	ID          uint
	Username    string
	NickName    string
	AuthorityId string
}

type CustomClaims

type CustomClaims struct {
	BaseClaims
	BufferTime int64
	jwt.StandardClaims
}

Custom claims structure

type JWT

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

func NewJWT

func NewJWT(jwt structs.JWT) *JWT

func (*JWT) CreateClaims

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

func (*JWT) CreateToken

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

CreateToken 创建一个token

func (*JWT) CreateTokenByOldToken

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

CreateTokenByOldToken 旧token 换新token 使用归并回源避免并发问题

func (*JWT) ParseToken

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

ParseToken 解析 token

type Util

type Util struct {
}

func (Util) GetClaims

func (Util) GetClaims(token string, jwt structs.JWT) (*CustomClaims, error)

func (Util) Logger

func (Util) Logger() logger.Interface

func (Util) RegisterMany

func (u Util) RegisterMany(ip string, port int32, password string, maxWorkerId int32, totalCount int32) []int32

func (Util) RegisterOne

func (u Util) RegisterOne(ip string, port int32, password string, maxWorkerId int32) int32

func (Util) UnRegister

func (Util) UnRegister()

func (Util) Validate

func (Util) Validate(workerId int32) int32

Jump to

Keyboard shortcuts

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