jwt_util

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// jwt subject
	USER = "user"

	UserTokenTimeout      = int64(60 * 60 * 24) // 1天
	BufferTime            = int64(60 * 60 * 2)
	UserLoginTokenTimeout = int64(60 * 5) // 5 min
)

Variables

View Source
var (
	ErrTokenExpired     = errors.New("token is expired")
	ErrTokenNotValidYet = errors.New("token not active yet")
	ErrTokenMalformed   = errors.New("that's not even a token")
	ErrTokenInvalid     = errors.New("couldn't handle this token")
)

Functions

func InitUserJWT

func InitUserJWT(key string)

Types

type CustomClaims

type CustomClaims struct {
	UserID     string `json:"userId"` // 用户ID
	BufferTime int64  `json:"bufferTime"`
	jwt.StandardClaims
}

func GenerateToken

func GenerateToken(userID string, timeout int64) (*CustomClaims, string, error)

func ParseToken

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

Jump to

Keyboard shortcuts

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