Documentation ¶
Overview ¶
Package ratelimit provides a simple window-based rate limiter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct { sync.Mutex WindowLimits []WindowLimit // contains filtered or unexported fields }
Limiter is a simple rate limiter with one or more fixed windows, e.g. the last minute/hour/day/week, working on three classes/subnets of an IP.
func (*Limiter) Add ¶
Add attempts to consume "n" items from the rate limiter. If the total for this key and this interval would exceed limit, "n" is not counted and false is returned. If now represents a different time interval, all counts are reset.
Click to show internal directories.
Click to hide internal directories.