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 is an in-memory sliding-window rate limiter keyed by string.
func (*Limiter) Allow ¶
Allow returns true if the key has not exceeded the rate limit. If allowed, the attempt is recorded.
func (*Limiter) AllowWithRetryAfter ¶ added in v0.3.0
AllowWithRetryAfter behaves like Allow but additionally returns the duration the caller must wait before the next attempt could succeed (rounded up to the next whole second so callers can use it for the Retry-After response header). When the request is allowed, the returned duration is zero. The returned duration is conservative (>= one second when blocked) so that a Retry-After header always communicates a meaningful, RFC 7231 §7.1.3-compatible delay.
Click to show internal directories.
Click to hide internal directories.