Documentation
¶
Overview ¶
Package ratelimit provides an in-memory token bucket rate limiter. Each key (IP or tenant) gets an independent bucket that refills at a configured rate. Stale buckets are cleaned up periodically.
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 is a thread-safe token bucket rate limiter keyed by string.
func New ¶
New creates a Limiter that allows `rate` requests/second with a burst of `burst`. It starts a background goroutine to evict stale entries every minute.
func (*Limiter) Allow ¶
Allow reports whether a request for the given key is allowed. It consumes one token if available.
Click to show internal directories.
Click to hide internal directories.