Documentation
¶
Overview ¶
Package ratelimiter implements two common rate limiters; queue and token/leaky bucket.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LeakyBucket ¶
type LeakyBucket struct {
NumActions int
Quantum time.Duration
Tokens map[string]*Token
Now func() time.Time
}
LeakyBucket implements the token bucket rate limiting algorithm.
func NewLeakyBucket ¶
func NewLeakyBucket(numActions int, quantum time.Duration) *LeakyBucket
NewLeakyBucket returns a new token bucket rate limiter. The rate is formed by `numActions` and `quantum`; the resulting rate is numActions/quantum.
func (*LeakyBucket) Check ¶
func (lb *LeakyBucket) Check(id string) bool
Check returns true if an id has exceeded the rate limit, and false otherwise.
type Queue ¶
type Queue struct {
NumberOfActions int
Quantum time.Duration
Limits map[string]collections.Queue
Now func() time.Time
}
Queue is a simple implementation of a rate checker.
type RateLimiter ¶
type RateLimiter interface {
// Check returns for a given id `true` if that id is _above_ the rate limit, and false otherwise.
Check(string) bool
}
RateLimiter is a type that can be used as a rate limiter.
Click to show internal directories.
Click to hide internal directories.