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 ¶
- func BuildKeys(limiter *config.Limiter, r engine.Request) [][]string
- func LimitByRequest(limiter *config.Limiter, r engine.Request) *errors.HTTPError
- func LimitHandler(limiter *config.Limiter) echo.MiddlewareFunc
- func LimitMiddleware(limiter *config.Limiter) echo.MiddlewareFunc
- func RemoteIP(ipLookups []string, r engine.Request) string
- func StringInSlice(sliceString []string, needle string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildKeys ¶
BuildKeys generates a slice of keys to rate-limit by given config and request structs.
func LimitByRequest ¶
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 StringInSlice ¶
StringInSlice finds needle in a slice of strings.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.