utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRefreshToken

func GenerateRefreshToken(userID uint, username string, roleID uint, jwtConfig *config.JWTConfig) (string, error)

GenerateRefreshToken 生成刷新令牌

func GenerateSignedToken

func GenerateSignedToken(email string, timestamp int64, prefix string, cfg *config.JWTConfig) string

func GenerateToken

func GenerateToken(userID uint, username string, roleID uint, jwtConfig *config.JWTConfig) (string, error)

GenerateToken 生成JWT令牌

func IsTokenExpired

func IsTokenExpired(timestamp int64, expirationHours int) bool

func RefreshAccessToken

func RefreshAccessToken(refreshTokenString string, jwtConfig *config.JWTConfig) (string, error)

RefreshAccessToken 使用刷新令牌生成新的访问令牌

func ValidateRefreshToken

func ValidateRefreshToken(tokenString string, jwtConfig *config.JWTConfig) bool

ValidateRefreshToken 验证刷新令牌是否有效

func ValidateSignedToken

func ValidateSignedToken(token string, prefix string, cfg *config.JWTConfig) (string, int64, error)

func ValidateToken

func ValidateToken(tokenString string, jwtConfig *config.JWTConfig) bool

ValidateToken 验证JWT令牌是否有效

func WordCount

func WordCount(images []models.Image) map[string]int

Types

type JWTClaims

type JWTClaims struct {
	UserID   uint   `json:"user_id"`
	Username string `json:"username"`
	RoleName string `json:"role_name"`
	RoleID   uint   `json:"role_id"`
	jwt.RegisteredClaims
}

JWT自定义声明结构体

func ParseToken

func ParseToken(tokenString string, jwtConfig *config.JWTConfig) (*JWTClaims, error)

ParseToken 解析JWT令牌

type RefreshTokenClaims

type RefreshTokenClaims struct {
	UserID    uint   `json:"user_id"`
	Username  string `json:"username"`
	RoleID    uint   `json:"role_id"`
	TokenType string `json:"token_type"`
	jwt.RegisteredClaims
}

RefreshTokenClaims 刷新令牌声明结构体

func ParseRefreshToken

func ParseRefreshToken(tokenString string, jwtConfig *config.JWTConfig) (*RefreshTokenClaims, error)

ParseRefreshToken 解析刷新令牌

Jump to

Keyboard shortcuts

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