Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter manages rate limiting state and cleanup for multiple keys. It uses a token bucket algorithm to enforce per-key rate limits. Limiter is safe for concurrent use.
func NewLimiter ¶
NewLimiter creates a new rate limiter. requestsPerMinute: number of requests allowed per minute per key (e.g., 1000 = ~16.67 req/sec)
The limiter: - Uses token bucket algorithm allowing bursts up to the full minute limit - Periodically cleans up limiters for keys inactive for more than staleAge - Is safe for concurrent use
Important: Call Stop() when done to prevent goroutine leaks.
type Option ¶
type Option func(*Limiter)
Option is a functional option for configuring a Limiter
func WithCleanupInterval ¶
WithCleanupInterval sets how often to clean up stale limiters. Default: 10 minutes
func WithStaleAge ¶
WithStaleAge sets how long a limiter can be inactive before being removed. Default: 1 hour