Versions in this module Expand all Collapse all v0 v0.3.0 Mar 15, 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