ratelimit

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimit bounds how often a caller may be served. It hands out one token bucket per key behind a hard cap on how many keys it will hold, so the registry itself cannot become an unbounded-memory attack surface. When the registry is full and cannot admit a new key, the caller is expected to fall back to a coarser, shared bucket rather than treat the key as unlimited or as permanently refused.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

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

Registry hands out one token bucket per key, with a hard cap on how many keys it will hold.

func NewRegistry

func NewRegistry(limit rate.Limit, burst, maxKeys int) *Registry

NewRegistry builds a Registry whose limiters each allow limit tokens per second with the given burst, holding at most maxKeys keys at once.

func (*Registry) Allow

func (r *Registry) Allow(key string, now time.Time) (allowed, keyed bool)

Allow reports whether key may be served at now. The second return is false when the registry is at capacity and could not admit key — the caller must then fall back to its global bucket (see the package comment).

func (*Registry) Len

func (r *Registry) Len() int

Len reports how many keys are currently held. Test and diagnostic use only.

Jump to

Keyboard shortcuts

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