ratelimit

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonCooldown      = "cooldown"
	ReasonLimitExceeded = "limit_exceeded"
)

Variables

This section is empty.

Functions

func Remaining added in v0.74.0

func Remaining(limit, used int) int

Remaining returns the non-negative requests left given a limit and used count.

Types

type Limit added in v0.74.0

type Limit struct {
	Limit    int
	Window   time.Duration
	Cooldown time.Duration
}

Limit configures a named rate-limit bucket: at most Limit requests per Window, with an optional Cooldown applied once the limit is hit. It is the single shared limit type consumed by the memory and redis limiter backends and the HTTP layer.

func LookupLimit added in v0.74.0

func LookupLimit(limits map[string]Limit, bucket string) (Limit, bool)

LookupLimit resolves the Limit for a bucket from a limits map: the bucket's own entry, else the "default" entry, else a conservative built-in fallback (found is false only for that fallback). Shared by the memory and redis backends.

type Result

type Result struct {
	Allowed    bool
	RetryAfter time.Duration
	Reason     string
	Limit      int
	Remaining  int
	Window     time.Duration
	Cooldown   time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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