ratelimit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

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.

Jump to

Keyboard shortcuts

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