ratelimit

package
v0.0.0-...-30a80d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2022 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ratelimit provides a basic rate limiter middleware for net/http.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// Limiter is the rate limiter used to limit requests.
	Limiter *rate.Limiter

	// SetRetryAfter sets the Retry-After header on rate limited
	// responses. If false, the header is not set.
	SetRetryAfter bool

	// SetXLimit sets the X-RateLimit-* headers on rate limited
	SetXLimit bool

	// OnLimit is called when a request is rate limited.
	// If nil, http.StatusTooManyRequests (429) is returned.
	OnLimit func(w http.ResponseWriter, r *http.Request)

	// Next is the Next handler in the chain.
	Next http.HandlerFunc
}

Handler is a net/http middleware that rate limits requests based on the configured limiter.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler and rate limits requests based on the configured limiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL