Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( WithLimiter = func(limiter rate.Limiter) OptionFiber { return func(o *optionFiber) { o.limiter = limiter } } WithConfig = func(config Config) OptionFiber { return func(o *optionFiber) { o.config = config } } )
View Source
var DefaultConfig = Config{ CommonConfig: middlewares.DefaultCommonConfig, ErrHandler: func(ctx *sysfiber.Ctx, conf *Config, err error) error { middlewares.ErrorThrottleHandler( conf.Logger, middlewares.Client{ IP: ctx.IP(), Path: ctx.Path(), }, err, time.Now(), ) ctx.Response().Header.Add(middlewares.HeaderRetryAfter, middlewares.DefaultRetryAfter) return ctx.SendStatus(http.StatusTooManyRequests) }, LimitHandler: func(c *sysfiber.Ctx, conf *Config, now time.Time) error { middlewares.LimitHandler( conf.Logger, middlewares.Client{ IP: c.IP(), Path: c.Path(), }, now, ) var wtrStr string = middlewares.DefaultRetryAfter wtr := time.Since(now).Round(time.Second) if wtr > time.Second { wtrStr = strconv.Itoa(2 * int(wtr.Seconds())) } c.Response().Header.Set(middlewares.HeaderRetryAfter, wtrStr) return c.SendStatus(http.StatusTooManyRequests) }, }
Functions ¶
func RateLimit ¶ added in v0.1.2
func RateLimit(ops ...OptionFiber) sysfiber.Handler
RateLimitWithConfig echo middleware with custom conf
Types ¶
type OptionFiber ¶ added in v0.1.2
type OptionFiber func(*optionFiber)
Click to show internal directories.
Click to hide internal directories.