ratelimit

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBuckets is the maximum number of rate limit buckets kept in memory.
	// When exceeded, stale buckets (fully refilled and older than their window) are evicted.
	MaxBuckets = 10000
)

Variables

This section is empty.

Functions

func ParseWindow

func ParseWindow(s string) (time.Duration, error)

ParseWindow converts a window string like "1m", "30s", "1h" to a Duration.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter implements a token-bucket rate limiter keyed by scope and agent.

func New

func New() *Limiter

New creates a new rate limiter.

func (*Limiter) Allow

func (l *Limiter) Allow(key string, maxRequests int, window time.Duration) error

Allow checks whether a request identified by key is within the rate limit. maxRequests is the maximum number of requests allowed in the given window. Returns nil if allowed, or an error describing the limit.

func (*Limiter) BucketCount added in v0.5.0

func (l *Limiter) BucketCount() int

BucketCount returns the current number of tracked buckets (for testing).

Jump to

Keyboard shortcuts

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