ratelimit

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP extracts the client IP from the request, respecting reverse proxy headers.

Types

type Limiter

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

Limiter implements a per-IP token bucket rate limiter.

func New

func New(rate float64, burst int) *Limiter

New creates a rate limiter allowing rate tokens per second with the given burst capacity.

func (*Limiter) Allow

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

Allow consumes one token for the given IP and reports whether the request is allowed.

func (*Limiter) Middleware

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

Middleware wraps an http.Handler and rejects requests that exceed the rate limit with a 429 status code.

func (*Limiter) Start

func (l *Limiter) Start(ctx context.Context)

Start launches a background goroutine that evicts inactive visitors every 60 seconds. It stops when ctx is cancelled.

Jump to

Keyboard shortcuts

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