jwt

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const TokenExpireDuration = time.Hour * 24 * 30

TokenExpireDuration 定义JWT的过期时间

Variables

This section is empty.

Functions

func GenToken

func GenToken(accessKey string, secretKey string, reqBody string) (Token string, err error)

GenToken 生成token

Types

type MyClaims

type MyClaims struct {
	AccessKey string `json:"access_key"`
	ReqBody   string `json:"req_body"`
	jwt.StandardClaims
}

MyClaims 自定义声明结构体并内嵌jwt.StandardClaims jwt包自带的jwt.StandardClaims只包含了官方字段 我们这里需要额外记录UserID字段和Username,所以要自定义结构体 如果想要保存更多信息,都可以添加到这个结构体中

func ParseToken

func ParseToken(tokenString string) (claims *MyClaims, err error)

Jump to

Keyboard shortcuts

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