jwt_util

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// jwt subject
	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) error

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