ratelimit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ratelimit provides a per-key token-bucket limiter, used to cap the ingest rate per source so one provider cannot overwhelm the gateway.

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 caps requests per key with an independent token bucket for each key. A non-positive rate disables limiting, and a nil *Limiter allows everything, so callers can construct one unconditionally.

func New

func New(perSecond float64, burst int) *Limiter

New builds a limiter allowing perSecond requests per key with the given burst. A burst below 1 defaults to one second of capacity. A non-positive rate makes every Allow return true.

func (*Limiter) Allow

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

Allow reports whether a request for key may proceed now.

Jump to

Keyboard shortcuts

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