Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmptyUID = errors.New("capacitor: uid must not be empty") ErrEvalResponse = errors.New("capacitor: invalid eval response") )
Functions ¶
func KeyFromRemoteIP ¶
KeyFromRemoteIP extracts the IP from RemoteAddr, stripping the port.
func NewMiddleware ¶
NewMiddleware returns standard net/http middleware that rate-limits requests using the provided capacitor instance.
Types ¶
type Capacitor ¶
type Capacitor struct {
// contains filtered or unexported fields
}
capacitor implements leaky bucket using valkey-go native client.
type Config ¶
func DefaultConfig ¶
func DefaultConfig() Config
type FallbackStrategy ¶
type FallbackStrategy int
const ( FallbackFailOpen FallbackStrategy = iota FallbackFailClosed )
type KeyFunc ¶
KeyFunc extracts the rate-limit key from an incoming request.
func KeyFromHeader ¶
KeyFromHeader returns a KeyFunc that reads the given header.
type MetricsCollector ¶
type MiddlewareOption ¶
type MiddlewareOption func(*mw)
MiddlewareOption configures the HTTP middleware.
func WithDenyHandler ¶
func WithDenyHandler(h http.Handler) MiddlewareOption
WithDenyHandler replaces the default 429 response handler.
func WithKeyFunc ¶
func WithKeyFunc(fn KeyFunc) MiddlewareOption
WithKeyFunc sets the function used to derive the rate-limit key. Defaults to KeyFromRemoteIP.
type Option ¶
type Option func(*Capacitor)
func WithFallback ¶
func WithFallback(s FallbackStrategy) Option
func WithLogger ¶
func WithMetrics ¶
func WithMetrics(m MetricsCollector) Option
Click to show internal directories.
Click to hide internal directories.