limiter

package module
v0.0.0-...-ee68cfb Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: MIT Imports: 4 Imported by: 0

README

Buffalo rate-limiter

Rate-limiter middleware for buffalo based on didip/tollbooth

Usage and config

Add the middleware in your App() like this:

import (
...
limiter "github.com/alcalbg/buffalo-rate-limiter-mw"
...
)

...

// List of places to look up IP addresses
// If your application is behind a proxy, set "X-Forwarded-For" first
// If you use CloudFlare, set "CF-Connecting-Ip" first  
IPLookups := []string{"RemoteAddr", "X-Forwarded-For", "X-Real-IP"}

// Maximum 5 requests per second
maxRequestsPerSecond = 5

app.Use(limiter.Limiter(maxRequestsPerSecond, IPLookups))

If you need throttling on a grouped routes then:

auth := app.Group("/auth")
auth.Use(limiter.Limiter(5, []string{"CF-Connecting-Ip"}))
auth.GET("/login", AuthNew)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Limiter

func Limiter(maxPerSecond float64, IPLookups []string) buffalo.MiddlewareFunc

Limiter is a middleware that performs rate-limiting

Types

This section is empty.

Jump to

Keyboard shortcuts

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