util

package
v0.0.0-...-e778533 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenExpired     error = errors.New("Token已失效")
	ErrTokenNotValidYet error = errors.New("Token未激活")
	ErrTokenMalformed   error = errors.New("Token不合法")
	ErrTokenInvalid     error = errors.New("Token解析失败")
)

一些常量

Functions

func RandStringRunes

func RandStringRunes(n int) string

RandStringRunes 返回随机字符串

Types

type CustomClaims

type CustomClaims struct {
	ID       uint   `json:"UserId"`
	UserName string `json:"UserName"`
	Status   string `json:"Status"`
	Avatar   string `json:"Avatar"`
	jwt.StandardClaims
}

载荷,可以加一些自己需要的信息

func NewCustomClaims

func NewCustomClaims(user *model.User) *CustomClaims

新建一个customClaims实例

type JWT

type JWT struct {
	SigningKey []byte
}

JWT 签名结构

func NewJWT

func NewJWT() *JWT

新建一个jwt实例

func (*JWT) CreateToken

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

CreateToken 生成一个token

func (*JWT) ParseToken

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

解析Tokne

func (*JWT) RefreshToken

func (j *JWT) RefreshToken(tokenString string) (string, error)

更新token

Jump to

Keyboard shortcuts

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