Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SlidingWindow ¶
SlidingWindow implements a fixed-size sliding window for rate limiting.
func New ¶
func New(windowSize, bucketSize time.Duration, bucketCount int) (*SlidingWindow, error)
NewSlidingWindow creates a new sliding window with the given window size, bucket size and bucket count. Window size must be divisible by bucket size.
func (*SlidingWindow) Allow ¶
func (sw *SlidingWindow) Allow() bool
Allow reports whether a new event should be allowed, and if so increments the
func (*SlidingWindow) BucketCount ¶
func (sw *SlidingWindow) BucketCount(idx int) int
BucketCount returns the current count for the given bucket index.
func (*SlidingWindow) Count ¶
func (sw *SlidingWindow) Count(d time.Duration) int
Count returns the total count for the given duration
func (*SlidingWindow) Reset ¶
func (sw *SlidingWindow) Reset()
Reset resets the counts in all buckets to 0.
Click to show internal directories.
Click to hide internal directories.