Documentation
¶
Index ¶
Constants ¶
View Source
const LuaScriptForRedis string = `` /* 1344-byte string literal not displayed */
LuaScriptForRedis script loading for cluster client and ring client for nodes changing. based on links below https://github.com/thunks/thunk-ratelimiter https://github.com/thunks/thunk-ratelimiter/blob/master/ratelimiter.lua
Variables ¶
View Source
var ( // DefaultRateLimiterConfig is the default rate limit middleware config. DefaultRateLimiterConfig = RateLimiterConfig{ Skipper: echo.DefaultSkipper, Max: 100, Duration: time.Minute * 1, Prefix: "LIMIT", Client: nil, SkipRateLimiterInternalError: false, LimiterKeyGenerator: func(c echo.Context) (string, []int) { return c.RealIP() + `@` + c.Method(), nil }, } )
Functions ¶
func RateLimiter ¶
func RateLimiter() echo.MiddlewareFunc
RateLimiter returns a rate limit middleware.
func RateLimiterWithConfig ¶
func RateLimiterWithConfig(config RateLimiterConfig) echo.MiddlewareFunc
RateLimiterWithConfig returns a RateLimiter middleware with config. See: `RateLimiter()`.
Types ¶
type RateLimiterConfig ¶
type RateLimiterConfig struct {
// Skipper defines a function to skip middleware.
Skipper echo.Skipper
// The max count in duration for no policy, default is 100.
Max int
// Count duration for no policy, default is 1 Minute.
Duration time.Duration
// Prefix key prefix, default is "LIMIT:".
Prefix string
// Use a redis client for limiter, if omit, it will use a memory limiter.
Client RedisClient
//If request gets a internal limiter error, just skip the limiter and let it go to next middleware
SkipRateLimiterInternalError bool
LimiterKeyGenerator func(c echo.Context) (limiterKey string, policy []int)
}
RateLimiterConfig defines the config for RateLimiter middleware.
Click to show internal directories.
Click to hide internal directories.