Help us shape the future of Go! Take the 2026 Go Developer Survey

ratelimit

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ratelimit provides a per-IP token bucket rate limiter keyed by /32 for IPv4 and /64 for IPv6.

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
}

func New

func New(limit rate.Limit, burst int, opts ...Option) *Limiter

New creates a Limiter, panics on invalid arguments.

func (*Limiter) Allow

func (l *Limiter) Allow(addr net.Addr) bool

Allow reports whether a request from addr may proceed; non-IP addresses are always allowed.

type Option

type Option func(*options)

func WithAllow

func WithAllow(prefixes ...netip.Prefix) Option

WithAllow exempts addresses within the given prefixes from limiting.

func WithMaxEntries

func WithMaxEntries(n int) Option

WithMaxEntries caps the number of tracked keys; new keys beyond it are not limited.

Jump to

Keyboard shortcuts

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