Version: v2.2.2+incompatible Latest Latest

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

Go to latest
Published: Nov 7, 2018 License: MIT Imports: 4 Imported by: 0




This section is empty.


This section is empty.


func DefaultErrorHandler

func DefaultErrorHandler(c *gin.Context, err error)

DefaultErrorHandler is the default ErrorHandler used by a new Middleware.

func DefaultKeyGetter

func DefaultKeyGetter(c *gin.Context) string

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

func DefaultLimitReachedHandler

func DefaultLimitReachedHandler(c *gin.Context)

DefaultLimitReachedHandler is the default LimitReachedHandler used by a new Middleware.

func NewMiddleware

func NewMiddleware(limiter *limiter.Limiter, options ...Option) gin.HandlerFunc

NewMiddleware return a new instance of a basic HTTP middleware.


type ErrorHandler

type ErrorHandler func(c *gin.Context, err error)

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

type KeyGetter

type KeyGetter func(c *gin.Context) string

KeyGetter will define the rate limiter key given the gin Context

type LimitReachedHandler

type LimitReachedHandler func(c *gin.Context)

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

Middleware is the middleware for basic http.Handler.

func (*Middleware) Handle

func (middleware *Middleware) Handle(c *gin.Context)

Handle gin 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 WithKeyGetter

func WithKeyGetter(KeyGetter 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
t or T : Toggle theme light dark auto
y or Y : Canonical URL