Documentation
¶
Overview ¶
Package ratelimit limits the requests of each client with a token bucket per key (golang.org/x/time/rate), in memory and bounded: an idle bucket is forgotten, and the number of buckets is capped.
Index ¶
Constants ¶
View Source
const DefaultMaxKeys = 100_000
DefaultMaxKeys is a cap on the keys a Limiter tracks at once: 17 MB of heap, as measured with IPv6 prefixes as keys.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decision ¶
type Decision struct {
// Allowed reports whether the request may be served.
Allowed bool
// Remaining is the number of requests the client may still send now.
Remaining int
// Reset is how long until one more request is restored, rounded up to
// the second: within it, the client may send no more than Remaining.
// It is zero when the whole quota is available.
Reset time.Duration
}
Decision is the answer of a Limiter to one request.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter applies a Policy to each key on its own. It is safe for concurrent use.
type Policy ¶
type Policy struct {
// Quota is the number of requests of a window, at least one.
Quota int
// Window is the period over which Quota is restored, at least one
// second.
Window time.Duration
}
Policy is a quota of requests per window. A client may spend the whole quota at once; it is then restored at an even pace over the window.
Click to show internal directories.
Click to hide internal directories.