Versions in this module Expand all Collapse all v0 v0.18.0 Oct 20, 2026 v0.17.0 Oct 19, 2026 v0.16.0 Oct 14, 2026 v0.15.0 Oct 13, 2026 v0.14.0 Oct 11, 2026 Changes in this version + const DefaultMaxKeys + var ErrClosed = errors.New("ratelimit: storage closed") + var ErrTooManyKeys = errors.New("ratelimit: too many tracked keys") + func ForwardedClientIP(trustedProxies ...string) (func(*http.Request) string, error) + func PeerIP(r *http.Request) string type KeyFunc + func ForwardedIPKey(trustedProxies ...string) (KeyFunc, error) type MemoryOption + func WithMaxKeys(n int) MemoryOption type Option + func WithFailOpen() Option + func WithLogger(logger *slog.Logger) Option v0.13.0 Oct 7, 2026 v0.12.0 Oct 6, 2026 v0.11.0 Oct 3, 2026 v0.10.0 Sep 6, 2026 Changes in this version + var ErrRateLimitExceeded = errors.New("rate limit exceeded") + var ErrStorageFailure = errors.New("rate limit storage failure") + func NewRedisClient(cfg *RedisConfig) redis.UniversalClient + type CoreAPIResolver struct + func NewCoreAPIResolver(store coreapi.PolicyStore, opts ...CoreAPIResolverOption) *CoreAPIResolver + func (r *CoreAPIResolver) GetPolicyForRequest(ctx context.Context, req *http.Request) *coreapi.RateLimitPolicy + func (r *CoreAPIResolver) InvalidateCache(clientID string) + func (r *CoreAPIResolver) Resolve(ctx context.Context, key string, req *http.Request) Limit + type CoreAPIResolverOption func(*CoreAPIResolver) + func WithResolverCache(ttl time.Duration) CoreAPIResolverOption + type KeyFunc func(r *http.Request) string + func ClientEndpointKey() KeyFunc + func ClientKey() KeyFunc + func CompositeKey() KeyFunc + func EndpointKey(inner KeyFunc) KeyFunc + func IPKey() KeyFunc + func PrincipalEndpointKey() KeyFunc + func PrincipalKey() KeyFunc + type Limit struct + Burst int + Period time.Duration + Rate int + func DefaultLimit() Limit + func PerHour(n int) Limit + func PerMinute(n int) Limit + func PerSecond(n int) Limit + type LimitResolver interface + Resolve func(ctx context.Context, key string, r *http.Request) Limit + type Limiter struct + func New(storage Storage, opts ...Option) *Limiter + func (l *Limiter) Allow(r *http.Request) (Result, error) + func (l *Limiter) Close() error + func (l *Limiter) Middleware() func(http.Handler) http.Handler + type MemoryOption func(*MemoryStorage) + func WithCleanupInterval(d time.Duration) MemoryOption + type MemoryStorage struct + func NewMemoryStorage(opts ...MemoryOption) *MemoryStorage + func (m *MemoryStorage) Allow(ctx context.Context, key string, limit Limit) (Result, error) + func (m *MemoryStorage) Close() error + func (m *MemoryStorage) Reset(ctx context.Context, key string) error + type Option func(*Limiter) + func WithKeyFunc(keyFunc KeyFunc) Option + func WithLimit(limit Limit) Option + func WithObservability(obs *observability.Observability) Option + func WithResolver(resolver LimitResolver) Option + type RedisConfig struct + Addr string + Cluster bool + ClusterAddrs []string + DB int + Password string + PoolSize int + type RedisOption func(*RedisStorage) + func WithKeyPrefix(prefix string) RedisOption + type RedisStorage struct + func NewRedisStorage(client redis.UniversalClient, opts ...RedisOption) *RedisStorage + func (r *RedisStorage) Allow(ctx context.Context, key string, limit Limit) (Result, error) + func (r *RedisStorage) Close() error + func (r *RedisStorage) Reset(ctx context.Context, key string) error + type Result struct + Allowed bool + Remaining int + ResetAt time.Time + RetryAfter time.Duration + type StaticResolver struct + Limit Limit + func (s *StaticResolver) Resolve(ctx context.Context, key string, r *http.Request) Limit + type Storage interface + Allow func(ctx context.Context, key string, limit Limit) (Result, error) + Close func() error + Reset func(ctx context.Context, key string) error + type TieredResolver struct + Default Limit + TierFunc func(ctx context.Context, key string, r *http.Request) string + Tiers map[string]Limit + func (t *TieredResolver) Resolve(ctx context.Context, key string, r *http.Request) Limit