Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(config Config) rex.Middleware
New creates a new RateLimit middleware with the given configuration.
Types ¶
type Config ¶
type Config struct {
// Rate is the number of requests allowed per second.
Rate float64
// Capacity is the maximum burst size.
Capacity float64
// KeyFunc generates a key for the request (e.g. IP address).
// Defaults to c.IP() if nil.
KeyFunc func(c *rex.Context) string
// Expiration is the duration after which an idle limiter is removed from memory.
// Default: 1 minute.
Expiration time.Duration
// ErrorHandler is called when the limit is exceeded.
// Default: returns 429 Too Many Requests.
ErrorHandler func(c *rex.Context) error
}
Config defines the configuration for the RateLimit middleware.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple token buckets (e.g. per IP).
func NewManager ¶
NewManager creates a new rate limiter manager. rate: tokens per second. capacity: max burst. expiration: how long to keep an idle bucket in memory.
Click to show internal directories.
Click to hide internal directories.