Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultRateLimiter ¶
func DefaultRateLimiter() zinc.Middleware
DefaultRateLimiter returns a rate limiter with default settings
func IPRateLimiter ¶
func IPRateLimiter(rate, capacity float64) zinc.Middleware
IPRateLimiter returns a rate limiter that limits by IP address
func RateLimiter ¶
func RateLimiter(config ...RateLimiterConfig) zinc.Middleware
RateLimiter returns a rate limiter middleware
Types ¶
type RateLimiterConfig ¶
type RateLimiterConfig struct {
// Rate is the token refill rate per second
Rate float64
// Capacity is the maximum number of tokens in the bucket
Capacity float64
// IPLookup is the function to extract IP address for per-IP rate limiting
// If nil, the rate limiter applies globally
IPLookup func(*zinc.Context) string
// KeyGenerator is a custom function to generate keys for rate limiting
// If nil and IPLookup is set, IP is used as key
// If both nil, global rate limiting is used
KeyGenerator func(*zinc.Context) string
// StatusCode is the response code when rate limit is exceeded
StatusCode int
// LimitReachedHandler is called when rate limit is reached
LimitReachedHandler zinc.RouteHandler
}
RateLimiterConfig contains configuration for the rate limiter middleware
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
TokenBucket represents a simple token bucket rate limiter
Click to show internal directories.
Click to hide internal directories.