Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRateLimiter ¶ added in v2.41.0
func NewRateLimiter(opts ...RateLimiterOption) func(http.Handler) http.Handler
NewRateLimiter returns an http.Handler middleware that rate-limits requests using a token-bucket algorithm per bucket key (default = IP address).
Types ¶
type KeyExtractor ¶ added in v2.41.0
KeyExtractor returns the rate-limit bucket key for a request.
type RateLimiterOption ¶ added in v2.41.0
type RateLimiterOption func(*rateLimiter)
RateLimiterOption configures the rate limiter.
func WithKeyExtractor ¶ added in v2.41.0
func WithKeyExtractor(fn KeyExtractor) RateLimiterOption
WithKeyExtractor replaces the default IP-based key extractor.
func WithMessage ¶ added in v2.41.0
func WithMessage(msg, code string) RateLimiterOption
WithMessage sets the error message and error code returned on limit.
func WithRate ¶ added in v2.41.0
func WithRate(rps float64, burst int) RateLimiterOption
WithRate sets the request-per-second limit and burst size.
func WithSkipPaths ¶ added in v2.41.0
func WithSkipPaths(paths ...string) RateLimiterOption
WithSkipPaths disables rate limiting for the given exact paths.
Click to show internal directories.
Click to hide internal directories.