jwt

package
v0.0.0-...-d993e0e Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

* @Author: drowningwhale 351231768@qq.com * @Date: 2023-10-01 13:45:12 * @LastEditors: drowningwhale 351231768@qq.com * @LastEditTime: 2023-10-01 19:25:47 * @FilePath: \go-coursed:\Data\Gitee\bluebell\pkg\jwt\jwt.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE

Index

Constants

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

Variables

View Source
var CustomSecret = []byte("真爱呀")

CustomSecret 用于加盐的字符串

Functions

func GenToken

func GenToken(UserID int, Username string) (string, error)

GenToken 生成JWT

Types

type CustomClaims

type CustomClaims struct {
	// 可根据需要自行添加字段
	UserID               int `json:"user_id"`
	jwt.RegisteredClaims     // 内嵌标准的声明
}

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

func ParseToken

func ParseToken(tokenString string) (*CustomClaims, error)

ParseToken 解析JWT

Jump to

Keyboard shortcuts

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