mid_gin

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const TokenExpireDuration = time.Hour * 24

TokenExpireDuration 定义JWT的过期时间, 这里以1天为例

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("this token could not handle")
)

Functions

func Cors

func Cors() gin.HandlerFunc

func CreateToken

func CreateToken(claims CustomClaims, key []byte) (string, error)

CreateToken 创建一个jwt token

func JWT

func JWT(key []byte) gin.HandlerFunc

Types

type CustomClaims

type CustomClaims struct {
	ID    int64  `json:"id"`
	Phone string `json:"phone"`
	jwt.StandardClaims
}

CustomClaims 教程地址: https://www.cnblogs.com/marshhu/p/12639633.html CustomClaims 自定义声明结构体并内嵌jwt.StandardClaims jwt.StandardClaims.ExpiresAt 设置过期时间, jwt.StandardClaims.Issuer 设置签发人 jwt包自带的jwt.StandardClaims只包含了官方字段 我们这里需要额外记录下面的几个字段, 所以要自定义结构体 如果想要保存更多信息, 都可以添加到这个结构体中

func ParseToken

func ParseToken(token string, key []byte) (*CustomClaims, error)

ParseToken 解析 token

Jump to

Keyboard shortcuts

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