Files
web/mw/rate_limiter_store.go
T

18 lines
721 B
Go
Raw Normal View History

package mw
import "context"
// RateLimiterStore is the pluggable backend for rate-limiting middleware.
// The key is determined by the caller (client IP or user ID).
//
// Shipped implementations:
// - [InMemoryRateLimiterStore] — per-key token bucket, stdlib only (this package)
// - einherjar/cache-valkey — Valkey-backed store for distributed deployments
//
// cache-valkey satisfies this interface via Go duck typing — it never imports web/mw.
type RateLimiterStore interface {
// Allow returns true when the request for the given key is within the rate limit.
// A non-nil error means the store is temporarily unavailable; middleware fails open.
Allow(ctx context.Context, key string) (bool, error)
}