Documentation
¶
Overview ¶
Package ratelimit provides token bucket rate limiting for agent requests. It implements a simple but effective rate limiting strategy that allows burst traffic while maintaining an average rate limit.
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 implements a token bucket rate limiter. It is safe for concurrent use.
func NewLimiter ¶
NewLimiter creates a new rate limiter with the given rate (requests per second) and burst size. Rate of 0 or negative disables rate limiting entirely. Burst must be at least 1 if rate limiting is enabled.
func (*Limiter) Allow ¶
Allow checks if a request can proceed immediately without waiting. It returns true if a token is available, false otherwise.
func (*Limiter) SetRate ¶
SetRate updates the rate limit. If rate is 0 or negative, rate limiting is disabled. This is useful for dynamic rate limit adjustments.