middleware

package
v0.0.0-...-d402f94 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     error = errors.New("token已过期,请重新登录")
	TokenNotValidYet error = errors.New("token无效,请重新登录")
	TokenMalformed   error = errors.New("token不正确,请重新登录")
	TokenInvalid     error = errors.New("这不是一个token,请重新登录")
)

定义错误

Functions

func Cors

func Cors() gin.HandlerFunc

Cors 处理跨域

func JWTAuth

func JWTAuth() gin.HandlerFunc

JWTAuth jwt中间件

func LoggerToFile

func LoggerToFile() gin.HandlerFunc

LoggerToFile 日志记录到文件

Types

type JWT

type JWT struct {
	// 秘钥,用以加密 JWT,读取配置信息 app.key
	SignKey []byte

	// 刷新 Token 的最大过期时间
	MaxRefresh time.Duration
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateToken

func (jwt *JWT) CreateToken(claims JWTCustomClaims) (string, error)

CreateToken 生成token

func (*JWT) ParseToken

func (jwt *JWT) ParseToken(token string) (*JWTCustomClaims, error)

ParseToken 解析token

type JWTCustomClaims

type JWTCustomClaims struct {
	UserID   string `json:"user_id"`
	Username string `json:"user_name"`
	jwtgo.RegisteredClaims
}

Jump to

Keyboard shortcuts

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