ratelimit

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter is a token-bucket rate limiter keyed by an arbitrary string (e.g. IP address).

func New

func New(rate float64, burst int) *Limiter

New returns a Limiter that allows rate tokens/second with a burst capacity of burst.

func (*Limiter) Allow

func (l *Limiter) Allow(key string) bool

Allow reports whether the request identified by key should be allowed.

func (*Limiter) Middleware

func (l *Limiter) Middleware(next http.Handler) http.Handler

Middleware returns an http.Handler that enforces the rate limit using the client's IP address as the bucket key. Requests that exceed the limit receive a 429 Too Many Requests response with a Retry-After: 1 header.

Jump to

Keyboard shortcuts

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