tollbooth_buffalo

package module
v0.0.0-...-72e0012 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 4 Imported by: 0

README

tollbooth_buffalo

Buffalo middleware for rate limiting HTTP requests.

Usage

import (
    "github.com/didip/tollbooth/v7"
	"github.com/didip/tollbooth/v7/limiter"
    "github.com/gobuffalo/envy"
)

var ENV = envy.Get("GO_ENV", "development")

func App() *buffalo.App {
	appOnce.Do(func() {
		app = buffalo.New(buffalo.Options{
			Env: ENV
		})

        lmt := tollbooth.NewLimiter(500, &limiter.ExpirableOptions{DefaultExpirationTTL: time.Minute})
		
        lmt.SetMethods([]string{"GET", "POST", "PUT", "DELETE"}).SetIPLookups([]string{"X-Forwarded-For", "X-Authorization", "RemoteAddr", "X-Real-IP"})
		
        lmt.SetMessage("Rate Limit Exceeded.").SetMessageContentType("application/json; charset=utf-8")

        app.Use(middlewares.RateLimitMiddleware(lmt))

		app.GET("/", HomeHandler)
    })

    return app
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitHandler

func LimitHandler(lmt *limiter.Limiter) buffalo.MiddlewareFunc

Types

This section is empty.

Jump to

Keyboard shortcuts

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