tollbooth_echo

package
v0.0.0-...-605330a Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2016 License: MIT Imports: 7 Imported by: 0

README

tollbooth_echo

Echo middleware for rate limiting HTTP requests.

Five Minutes Tutorial

package main

import (
	"time"

	"github.com/didip/tollbooth/thirdparty/tollbooth_echo"
	"github.com/didip/tollbooth"
	"github.com/webx-top/echo"
	"github.com/webx-top/echo/engine/standard"
)

func main() {
	e := echo.New()

	// Create a limiter struct.
	limiter := tollbooth.NewLimiter(1, time.Second)

	e.Get("/", echo.HandlerFunc(func(c echo.Context) error {
		return c.String(200, "Hello, World!")
	}), tollbooth_echo.LimitHandler(limiter))

	e.Run(standard.New(":4444"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKeys

func BuildKeys(limiter *config.Limiter, r engine.Request) [][]string

BuildKeys generates a slice of keys to rate-limit by given config and request structs.

func LimitByRequest

func LimitByRequest(limiter *config.Limiter, r engine.Request) *errors.HTTPError

LimitByRequest builds keys based on http.Request struct, loops through all the keys, and check if any one of them returns HTTPError.

func LimitHandler

func LimitHandler(limiter *config.Limiter) echo.MiddlewareFunc

func LimitMiddleware

func LimitMiddleware(limiter *config.Limiter) echo.MiddlewareFunc

func RemoteIP

func RemoteIP(ipLookups []string, r engine.Request) string

RemoteIP finds IP Address given http.Request struct.

func StringInSlice

func StringInSlice(sliceString []string, needle string) bool

StringInSlice finds needle in a slice of strings.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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