Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaxBody ¶
MaxBody returns middleware that rejects requests with a body exceeding maxBytes with 413 Payload Too Large.
func RateLimit ¶
func RateLimit(cfg RateLimitConfig) func(http.Handler) http.Handler
RateLimit returns middleware enforcing per-key rate limiting with token bucket.
Types ¶
type KeyFunc ¶
KeyFunc extracts a rate limit key from an HTTP request.
func HeaderKey ¶
HeaderKey returns a KeyFunc using the value of a request header as the key. Falls back to RemoteAddr if the header is absent.
func RemoteAddr ¶
func RemoteAddr() KeyFunc
RemoteAddr returns a KeyFunc that uses the request's RemoteAddr (without port).
func XForwardedFor ¶
XForwardedFor returns a KeyFunc that reads the client IP from X-Forwarded-For, but only if RemoteAddr is within a trusted CIDR range. Falls back to RemoteAddr if untrusted or if the X-Forwarded-For value is not a valid IP address.