tollbooth: github.com/didip/tollbooth Index | Files | Directories

package tollbooth

import "github.com/didip/tollbooth"

Package tollbooth provides rate-limiting logic to HTTP request handler.

Index

Package Files

tollbooth.go

func BuildKeys Uses

func BuildKeys(lmt *limiter.Limiter, r *http.Request) [][]string

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

func LimitByKeys Uses

func LimitByKeys(lmt *limiter.Limiter, keys []string) *errors.HTTPError

LimitByKeys keeps track number of request made by keys separated by pipe. It returns HTTPError when limit is exceeded.

func LimitByRequest Uses

func LimitByRequest(lmt *limiter.Limiter, w http.ResponseWriter, r *http.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 LimitFuncHandler Uses

func LimitFuncHandler(lmt *limiter.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler

LimitFuncHandler is a middleware that performs rate-limiting given request handler function.

func LimitHandler Uses

func LimitHandler(lmt *limiter.Limiter, next http.Handler) http.Handler

LimitHandler is a middleware that performs rate-limiting given http.Handler struct.

func NewLimiter Uses

func NewLimiter(max float64, tbOptions *limiter.ExpirableOptions) *limiter.Limiter

NewLimiter is a convenience function to limiter.New.

Directories

PathSynopsis
errorsPackage errors provide data structure for errors.
libstringPackage libstring provides various string related functions.
limiterPackage limiter provides data structure to configure rate-limiter.

Package tollbooth imports 7 packages (graph) and is imported by 59 packages. Updated 2019-11-12. Refresh now. Tools for package owners.