Documentation
¶
Overview ¶
Package ratelimit provides a shared rate limiter for broker API clients.
It wraps golang.org/x/time/rate to provide context-aware, per-broker request throttling. Multiple callers sharing the same Limiter are serialized correctly without exceeding the configured rate.
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 throttles API requests using a token-bucket algorithm.
func New ¶
New creates a Limiter that allows rps requests per second with the given burst size. Burst controls how many requests can fire at once before throttling kicks in.
func Shared ¶ added in v0.14.0
Shared returns the Limiter registered for (name, key), creating it on first access. Subsequent calls with the same (name, key) return the same *Limiter regardless of the rps/burst arguments — the values from the first caller win. Use when multiple clients must cooperatively stay under a shared upstream quota.