Documentation
¶
Overview ¶
Package tollbooth provides rate-limiting logic to HTTP request handler.
Index ¶
- func BuildKeys(limiter *limiter.Limiter, r *http.Request) [][]string
- func LimitByKeys(limiter *limiter.Limiter, keys []string) *errors.HTTPError
- func LimitByKeysWithTokenBucketTTL(limiter *limiter.Limiter, keys []string, bucketExpireTTL time.Duration) *errors.HTTPError
- func LimitByRequest(limiter *limiter.Limiter, r *http.Request) *errors.HTTPError
- func LimitFuncHandler(lmt *limiter.Limiter, nextFunc func(http.ResponseWriter, *http.Request)) http.Handler
- func LimitHandler(lmt *limiter.Limiter, next http.Handler) http.Handler
- func NewLimiter(max int64, ttl time.Duration, tbOptions *limiter.TokenBucketOptions) *limiter.Limiter
- func SetResponseHeaders(lmt *limiter.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 limiter 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 LimitByKeysWithTokenBucketTTL ¶
func LimitByKeysWithTokenBucketTTL(limiter *limiter.Limiter, keys []string, bucketExpireTTL time.Duration) *errors.HTTPError
LimitByKeysWithTokenBucketTTL functions just like LimitByKeys. But user can define a TTL for the token bucket to expire. This is to ensure that the middleware won't leak memory. 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(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 ¶
LimitHandler is a middleware that performs rate-limiting given http.Handler struct.
func NewLimiter ¶
func NewLimiter(max int64, ttl time.Duration, tbOptions *limiter.TokenBucketOptions) *limiter.Limiter
NewLimiter is a convenience function to limiter.New.
func SetResponseHeaders ¶
func SetResponseHeaders(lmt *limiter.Limiter, w http.ResponseWriter)
SetResponseHeaders configures X-Rate-Limit-Limit and X-Rate-Limit-Duration
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
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. |
|
Package limiter provides data structure to configure rate-limiter.
|
Package limiter provides data structure to configure rate-limiter. |