stdlib

package
v3.11.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 3 Imported by: 38

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)

DefaultErrorHandler is the default ErrorHandler used by a new Middleware.

func DefaultKeyGetter added in v3.10.0

func DefaultKeyGetter(limiter *limiter.Limiter) func(r *http.Request) string

DefaultKeyGetter is the default KeyGetter used by a new Middleware. It returns the Client IP address.

func DefaultLimitReachedHandler

func DefaultLimitReachedHandler(w http.ResponseWriter, r *http.Request)

DefaultLimitReachedHandler is the default LimitReachedHandler used by a new Middleware.

Types

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)

ErrorHandler is an handler used to inform when an error has occurred.

type KeyGetter added in v3.10.0

type KeyGetter func(r *http.Request) string

KeyGetter will define the rate limiter key given the gin Context.

type LimitReachedHandler

type LimitReachedHandler func(w http.ResponseWriter, r *http.Request)

LimitReachedHandler is an handler used to inform when the limit has exceeded.

type Middleware

type Middleware struct {
	Limiter        *limiter.Limiter
	OnError        ErrorHandler
	OnLimitReached LimitReachedHandler
	KeyGetter      KeyGetter
	ExcludedKey    func(string) bool
}

Middleware is the middleware for basic http.Handler.

func NewMiddleware

func NewMiddleware(limiter *limiter.Limiter, options ...Option) *Middleware

NewMiddleware return a new instance of a basic HTTP middleware.

func (*Middleware) Handler

func (middleware *Middleware) Handler(h http.Handler) http.Handler

Handler handles a HTTP request.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to define Middleware configuration.

func WithErrorHandler

func WithErrorHandler(handler ErrorHandler) Option

WithErrorHandler will configure the Middleware to use the given ErrorHandler.

func WithExcludedKey added in v3.5.0

func WithExcludedKey(handler func(string) bool) Option

WithExcludedKey will configure the Middleware to ignore key(s) using the given function.

func WithKeyGetter added in v3.10.0

func WithKeyGetter(handler KeyGetter) Option

WithKeyGetter will configure the Middleware to use the given KeyGetter.

func WithLimitReachedHandler

func WithLimitReachedHandler(handler LimitReachedHandler) Option

WithLimitReachedHandler will configure the Middleware to use the given LimitReachedHandler.

Jump to

Keyboard shortcuts

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