Documentation ¶
Overview ¶
Package tollbooth provides rate-limiting logic to HTTP request handler.
Index ¶
- func BuildKeys(limiter *config.Limiter, r *http.Request) [][]string
- func LimitByKeys(limiter *config.Limiter, keys []string) *errors.HTTPError
- func LimitByRequest(limiter *config.Limiter, r *http.Request) *errors.HTTPError
- func LimitFuncHandler(limiter *config.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler
- func LimitHandler(limiter *config.Limiter, next http.Handler) http.Handler
- func NewLimiter(max int64, ttl time.Duration) *config.Limiter
- func SetResponseHeaders(limiter *config.Limiter, w http.ResponseWriter)
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 LimitByKeys ¶
LimitByKeys keeps track number of request made by keys separated by pipe. It returns HTTPError when limit is exceeded.
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 LimitFuncHandler ¶
func LimitFuncHandler(limiter *config.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler
LimitFuncHandler is a middleware that performs rate-limiting given request handler function.
func LimitHandler ¶
LimitHandler is a middleware that performs rate-limiting given http.Handler struct.
func NewLimiter ¶
NewLimiter is a convenience function to config.NewLimiter.
func SetResponseHeaders ¶
func SetResponseHeaders(limiter *config.Limiter, w http.ResponseWriter)
SetResponseHeaders configures X-Rate-Limit-Limit and X-Rate-Limit-Duration
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package config provides data structure to configure rate-limiter.
|
Package config provides data structure to configure rate-limiter. |
Package errors provide data structure for errors.
|
Package errors provide data structure for errors. |
Package libstring provides various string related functions.
|
Package libstring provides various string related functions. |
thirdparty
|
|