ratelimiter

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const Lens scene.InfraName = "ratelimiter"

Variables

View Source
var (
	ErrInvalidLimit  = errors.New("ratelimiter: limit must be greater than zero")
	ErrInvalidWindow = errors.New("ratelimiter: window must be greater than zero")
	ErrEmptyKey      = errors.New("ratelimiter: key cannot be empty")
	ErrInvalidN      = errors.New("ratelimiter: n must be greater than zero and less than or equal to limit")
)

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Allowed bool

	// Limit is the quota limit of the current policy.
	Limit int
	// Remaining is the estimated units left after this decision.
	Remaining int

	// RetryAfter indicates how long caller should wait before retrying.
	// It is zero when Allowed is true.
	RetryAfter time.Duration
}

Decision is the verbose result of a rate limit attempt.

type Limiter

type Limiter interface {
	scene.Named
	Allow(ctx context.Context, key string) (Decision, error)
	AllowN(ctx context.Context, key string, n int) (Decision, error)
}

Limiter is a verbose and implementation-agnostic rate limiter contract.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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