ratelimit

package
v1.20.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 2 Imported by: 1

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL