middleware

package
v0.0.0-...-2cb3038 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

定义错误

Functions

func Cors

func Cors() gin.HandlerFunc

Cors 跨域中间件

func JwtToken

func JwtToken() gin.HandlerFunc

JwtToken jwt中间件 todo 优化此类代码

func Logger

func Logger() gin.HandlerFunc

Logger 日志中间件 todo 可考虑更换其他日志中间件

Types

type JWT

type JWT struct {
	JwtKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateToken

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

CreateToken 生成token

func (*JWT) ParserToken

func (j *JWT) ParserToken(tokenString string) error

ParserToken 解析token

type MyClaims

type MyClaims struct {
	Username string `json:"username"`
	jwt.RegisteredClaims
}

Jump to

Keyboard shortcuts

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