Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheHandler ¶ added in v1.51.1
CacheHandler is a middleware for caching static files for 1 year.
func CommonContentType ¶ added in v1.51.1
CommonContentType returns content-type for common extensions, ignoring OS settings.
Types ¶
type RateLimiter ¶ added in v1.39.4
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter imposes a rate limit per key.
func NewIPRateLimiter ¶
func NewIPRateLimiter(config RateLimiterConfig) *RateLimiter
NewIPRateLimiter constructs a RateLimiter that limits based on IP address.
func NewRateLimiter ¶ added in v1.39.4
func NewRateLimiter(config RateLimiterConfig, keyFunc func(*http.Request) (string, error)) *RateLimiter
NewRateLimiter constructs a RateLimiter.
func (*RateLimiter) Burst ¶ added in v1.39.4
func (rl *RateLimiter) Burst() int
Burst returns the number of events that happen before the rate limit.
func (*RateLimiter) Duration ¶ added in v1.39.4
func (rl *RateLimiter) Duration() time.Duration
Duration returns the amount of time required between events.
func (*RateLimiter) Limit ¶ added in v1.39.4
func (rl *RateLimiter) Limit(next http.Handler) http.Handler
Limit applies per-key rate limiting as an HTTP Handler.
func (*RateLimiter) Run ¶ added in v1.39.4
func (rl *RateLimiter) Run(ctx context.Context)
Run occasionally cleans old rate-limiting data, until context cancel.
type RateLimiterConfig ¶ added in v1.39.4
type RateLimiterConfig struct { Duration time.Duration `help:"the rate at which request are allowed" default:"5m"` Burst int `help:"number of events before the limit kicks in" default:"5" testDefault:"3"` NumLimits int `help:"number of clients whose rate limits we store" default:"1000" testDefault:"10"` }
RateLimiterConfig configures a RateLimiter.
Click to show internal directories.
Click to hide internal directories.