ratelimit

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is an in-memory, per-IP two-tier rate limiter. Each IP gets a short-term (per-second) and a long-term (per-minute) token bucket. A request must pass both to be allowed. Entries are evicted by Cleanup after being idle for a configurable duration.

func NewStore

func NewStore(rps float64, burst int, rpm float64, burstPerMin int) *Store

NewStore creates a Store with a per-second and per-minute limit. Pass rps <= 0 to disable rate limiting entirely (Allow always returns true).

func (*Store) Allow

func (s *Store) Allow(ip string) bool

Allow reports whether the given IP is within both rate limits.

func (*Store) Cleanup

func (s *Store) Cleanup(maxAge time.Duration)

Cleanup removes entries that have not been seen within maxAge. Call this periodically to prevent unbounded memory growth.

Jump to

Keyboard shortcuts

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