Documentation ¶
Index ¶
- Variables
- func IPTokenExtractor(c *gin.Context) string
- func NewRateLimiterMw(logger logging.Logger, next krakendgin.HandlerFactory) krakendgin.HandlerFactory
- func NewTriredRateLimiterMw(logger logging.Logger, next krakendgin.HandlerFactory) krakendgin.HandlerFactory
- func RateLimiterWrapperFromCfg(logger logging.Logger, logPrefix string, cfg router.RateLimitingConfig, ...) gin.HandlerFunc
- func TieredRateLimiterWrapperFromCfg(logger logging.Logger, logPrefix string, cfg router.TieredRateLimitConfig, ...) gin.HandlerFunc
- type EndpointMw
- func NewEndpointRateLimiterMw(tb *krakendrate.TokenBucket) EndpointMw
- func NewHeaderLimiterMw(header string, maxRate float64, capacity uint64) EndpointMwdeprecated
- func NewHeaderLimiterMwFromCfg(cfg router.RateLimitingConfig) EndpointMw
- func NewIpLimiterMw(maxRate float64, capacity uint64) EndpointMw
- func NewIpLimiterWithKeyMw(header string, maxRate float64, capacity uint64) EndpointMwdeprecated
- func NewIpLimiterWithKeyMwFromCfg(cfg router.RateLimitingConfig) EndpointMw
- func NewTieredTokenLimiterMw(tier_key_header string, limiters map[string]*TieredLimiter) EndpointMw
- func NewTokenLimiterMw(tokenExtractor TokenExtractor, limiterStore krakendrate.LimiterStore) EndpointMw
- type TieredLimiter
- type TokenExtractor
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
var HandlerFactory = NewRateLimiterMw(logging.NoOp, krakendgin.EndpointHandler)
HandlerFactory is the out-of-the-box basic ratelimit handler factory using the default krakend endpoint handler for the gin router
Functions ¶
func IPTokenExtractor ¶
IPTokenExtractor extracts the IP of the request
func NewRateLimiterMw ¶
func NewRateLimiterMw(logger logging.Logger, next krakendgin.HandlerFactory) krakendgin.HandlerFactory
NewRateLimiterMw builds a rate limiting wrapper over the received handler factory.
func NewTriredRateLimiterMw ¶
func NewTriredRateLimiterMw(logger logging.Logger, next krakendgin.HandlerFactory) krakendgin.HandlerFactory
func RateLimiterWrapperFromCfg ¶
func RateLimiterWrapperFromCfg(logger logging.Logger, logPrefix string, cfg router.RateLimitingConfig, handler gin.HandlerFunc, ) gin.HandlerFunc
func TieredRateLimiterWrapperFromCfg ¶
func TieredRateLimiterWrapperFromCfg(logger logging.Logger, logPrefix string, cfg router.TieredRateLimitConfig, handler gin.HandlerFunc, ) gin.HandlerFunc
Types ¶
type EndpointMw ¶
type EndpointMw func(gin.HandlerFunc) gin.HandlerFunc
EndpointMw is a function that decorates the received handlerFunc with some rateliming logic
func NewEndpointRateLimiterMw ¶
func NewEndpointRateLimiterMw(tb *krakendrate.TokenBucket) EndpointMw
NewEndpointRateLimiterMw creates a simple ratelimiter for a given handlerFunc
func NewHeaderLimiterMw
deprecated
func NewHeaderLimiterMw(header string, maxRate float64, capacity uint64) EndpointMw
NewHeaderLimiterMw creates a token ratelimiter using the value of a header as a token
Deprecated: Use NewHeaderLimiterMwFromCfg instead
func NewHeaderLimiterMwFromCfg ¶
func NewHeaderLimiterMwFromCfg(cfg router.RateLimitingConfig) EndpointMw
NewHeaderLimiterMwFromCfg creates a token ratelimiter using the value of a header as a token
func NewIpLimiterMw ¶
func NewIpLimiterMw(maxRate float64, capacity uint64) EndpointMw
NewIpLimiterMw creates a token ratelimiter using the IP of the request as a token
func NewIpLimiterWithKeyMw
deprecated
func NewIpLimiterWithKeyMw(header string, maxRate float64, capacity uint64) EndpointMw
NewIpLimiterWithKeyMw creates a token ratelimiter using the IP of the request as a token
Deprecated: Use NewIpLimiterWithKeyMwFromCfg instead
func NewIpLimiterWithKeyMwFromCfg ¶
func NewIpLimiterWithKeyMwFromCfg(cfg router.RateLimitingConfig) EndpointMw
NewIpLimiterWithKeyMwFromCfg creates a token ratelimiter using the IP of the request as a token
func NewTieredTokenLimiterMw ¶
func NewTieredTokenLimiterMw(tier_key_header string, limiters map[string]*TieredLimiter) EndpointMw
func NewTokenLimiterMw ¶
func NewTokenLimiterMw(tokenExtractor TokenExtractor, limiterStore krakendrate.LimiterStore) EndpointMw
NewTokenLimiterMw returns a token based ratelimiting endpoint middleware with the received TokenExtractor and LimiterStore
type TieredLimiter ¶
type TieredLimiter struct { Store krakendrate.LimiterStore TokenExtractor TokenExtractor }
User struct to hold rate limiter
type TokenExtractor ¶
TokenExtractor defines the interface of the functions to use in order to extract a token for each request
func HeaderTokenExtractor ¶
func HeaderTokenExtractor(header string) TokenExtractor
HeaderTokenExtractor returns a TokenExtractor that looks for the value of the designed header
func NewIPTokenExtractor ¶
func NewIPTokenExtractor(header string) TokenExtractor
NewIPTokenExtractor generates an IP TokenExtractor checking first for the contents of the passed header. If nothing is found there, the regular IPTokenExtractor function is called.
func ParamTokenExtractor ¶
func ParamTokenExtractor(param string) TokenExtractor
ParamTokenExtractor returns a TokenExtractor that uses a param a token
func TokenExtractorFromCfg ¶
func TokenExtractorFromCfg(cfg router.RateLimitingConfig) (TokenExtractor, error)
TokenExtractorFromCfg selects the token extractor to use from the input config