token

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultJWTSecret    = "default-secret-key" // Should be overridden in production | 生产环境应覆盖
	TikTokenLength      = 11                   // TikTok-style short ID length | Tik风格短ID长度
	TikCharset          = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	HashRandomBytesLen  = 16 // Random bytes length for hash token | 哈希Token的随机字节长度
	TimestampRandomLen  = 8  // Random bytes length for timestamp token | 时间戳Token的随机字节长度
	DefaultSimpleLength = 16 // Default simple token length | 默认简单Token长度
)

Constants for token generation | Token生成常量

Variables

View Source
var (
	ErrInvalidToken            = fmt.Errorf("invalid token")
	ErrUnexpectedSigningMethod = fmt.Errorf("unexpected signing method")
)

Error variables | 错误变量

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator Token generator | Token生成器

func NewGenerator

func NewGenerator(cfg *config.Config) *Generator

NewGenerator Creates a new token generator | 创建新的Token生成器

func (*Generator) Generate

func (g *Generator) Generate(loginID string, device string) (string, error)

Generate Generates token based on configured style | 根据配置的风格生成Token

func (*Generator) GetLoginIDFromJWT added in v0.1.2

func (g *Generator) GetLoginIDFromJWT(tokenStr string) (string, error)

GetLoginIDFromJWT Extracts login ID from JWT token | 从JWT Token中提取登录ID

func (*Generator) ParseJWT

func (g *Generator) ParseJWT(tokenStr string) (jwt.MapClaims, error)

ParseJWT Parses JWT token and returns claims | 解析JWT Token并返回声明

func (*Generator) ValidateJWT

func (g *Generator) ValidateJWT(tokenStr string) error

ValidateJWT Validates JWT token | 验证JWT Token

Jump to

Keyboard shortcuts

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