Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRateLimitExceeded = errors.New("rate limit exceeded")
Functions ¶
This section is empty.
Types ¶
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window is a time windows for counting events within a span of time. The windows slides forward in time so that it spans from the most recent event to size time in the past.
func NewWindow ¶
NewWindow creates a new Window that limits the number of events to maximum count of events within a duration of time. The capacity sets the maximum number of events, and size sets the span of time over which the events are counted.
func (*Window) Add ¶
Add attempts to append a new timestamp into the current window. Previously added values that are not not within `size` difference from the value being added are first removed. Add fails if adding the value would cause the window to exceed capacity.