Documentation
¶
Index ¶
Constants ¶
View Source
const ( DEFAULT_WINDOW = 60 DEFAULT_LIMIT = 60 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type UserCounter ¶
type UserCounter struct {
// contains filtered or unexported fields
}
type WindowCounter ¶
type WindowCounter struct {
// contains filtered or unexported fields
}
WindowCounter implements a simple window counter
func NewWindowCounter ¶
func NewWindowCounter(windowSeconds, limit int) *WindowCounter
NewWindowCounter returns a limiter that allows limit requests per key every windowSeconds. Non-positive values fall back to DEFAULT_WINDOW and DEFAULT_LIMIT. A window longer than a time.Duration can hold, about 292 years, is clamped to the longest one it can.
func (*WindowCounter) Allow ¶
func (rl *WindowCounter) Allow(userID string) bool
Allow charges one request to userID and reports whether it fits in the current window.
func (*WindowCounter) Exhausted ¶ added in v1.17.2
func (rl *WindowCounter) Exhausted(userID string) bool
Exhausted reports whether userID has spent its limit in the current window without charging it. It never creates or extends a counter, so peeking with a caller-supplied key cannot grow the map or prolong a lockout.
Click to show internal directories.
Click to hide internal directories.