Documentation ¶
Index ¶
- Constants
- Variables
- func GenToken(userID uint64, userName string, isAdmin bool) (aToken, rToken string, err error)
- func GenTokenWithExpire(userID uint64, userName string, isAdmin bool, tokenExpire time.Duration, ...) (aToken, rToken string, err error)
- func RefreshToken(aToken, rToken string) (newAToken, newRToken string, err error)
- func TokenExpire() int64
- type MyClaims
Constants ¶
View Source
const ( TokenExpireDuration = time.Hour * 24 * 2 RefreshTokenExpireDuration = time.Hour * 24 * 7 )
Variables ¶
View Source
var (
ErrTokenExpired = errors.New("token过期")
)
Functions ¶
func GenTokenWithExpire ¶
func RefreshToken ¶
RefreshToken 刷新AccessToken
func TokenExpire ¶
func TokenExpire() int64
Types ¶
type MyClaims ¶
type MyClaims struct { UserID uint64 `json:"userID"` UserName string `json:"userName"` IsAdmin bool `json:"isAdmin"` jwt.StandardClaims }
MyClaims 自定义声明结构体并内嵌jwt.StandardClaims jwt包自带的jwt.StandardClaims只包含了官方字段 我们这里需要额外记录一个UserID字段,所以要自定义结构体 如果想要保存更多信息,都可以添加到这个结构体中
func ParseToken ¶
ParseToken 解析JWT
Click to show internal directories.
Click to hide internal directories.