Documentation ¶
Index ¶
Constants ¶
View Source
const ( // EncoderBase32 specifies base32 encoding for token generation EncoderBase32 = "base32" // EncoderHex specifies hexadecimal encoding for token generation EncoderHex = "hex" // DefaultLength is the default token length in bytes DefaultLength = 16 // DefaultEncoder is the default encoding method DefaultEncoder = EncoderBase32 // MinLength is the minimum allowed token length in bytes MinLength = 16 // MaxLength is the maximum allowed token length in bytes MaxLength = 64 )
Variables ¶
View Source
var ( ErrTokenGeneration = errors.New("failed to generate token") ErrTokenNotFound = errors.New("token not found") ErrTokenExpired = errors.New("token expired") )
View Source
var DefaultOptions = Options{ Expiration: 10 * time.Minute, CleanupInterval: 5 * time.Minute, }
DefaultOptions provides recommended settings
Functions ¶
Types ¶
type Option ¶
type Option func(*config)
func WithEncoder ¶
WithEncoder sets the encoding format (EncoderBase32 or EncoderHex) If an invalid encoder is specified, DefaultEncoder will be used
func WithLength ¶
WithLength sets the token length in bytes If length is outside valid range (MinLength to MaxLength), DefaultLength will be used instead
type Options ¶
type Options struct { Expiration time.Duration // Token expiration duration CleanupInterval time.Duration // Cleanup interval duration }
Options configures the Store
type Store ¶
type Store struct { sync.RWMutex // Protects the tokens map // contains filtered or unexported fields }
Store is a thread-safe store for tokens
func NewTokenStore ¶
NewTokenStore creates a new token store with the given options
Click to show internal directories.
Click to hide internal directories.