From 9c0980e4248bc81fe563e5e9212b94b9e3f1b9e3 Mon Sep 17 00:00:00 2001 From: luk3skyw4lker Date: Tue, 23 Jul 2024 13:16:53 -0300 Subject: [PATCH] docs: update docs with MaxFunc parameter --- docs/middleware/limiter.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/middleware/limiter.md b/docs/middleware/limiter.md index fedc69f0d0..ab97620595 100644 --- a/docs/middleware/limiter.md +++ b/docs/middleware/limiter.md @@ -43,7 +43,7 @@ app.Use(limiter.New(limiter.Config{ return c.IP() == "127.0.0.1" }, Max: 20, - MaxCalculator: func(c fiber.Ctx) int { + MaxFunc: func(c fiber.Ctx) int { return 20 }, Expiration: 30 * time.Second, @@ -80,13 +80,13 @@ rate = weightOfPreviousWindow + current window's amount request. ## Dynamic limit -You can also calculate the limit dynamically using the MaxCalculator parameter. It's a function that receives the request's context as a parameter and allow you to calculate a different limit for each request separately. +You can also calculate the limit dynamically using the MaxFunc parameter. It's a function that receives the request's context as a parameter and allow you to calculate a different limit for each request separately. Example: ```go app.Use(limiter.New(limiter.Config{ - MaxCalculator: func(c fiber.Ctx) int { + MaxFunc: func(c fiber.Ctx) int { return getUserLimit(ctx.Param("id")) }, Expiration: 30 * time.Second, @@ -99,7 +99,7 @@ app.Use(limiter.New(limiter.Config{ |:-----------------------|:--------------------------|:--------------------------------------------------------------------------------------------|:-----------------------------------------| | Next | `func(fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` | | Max | `int` | Max number of recent connections during `Expiration` seconds before sending a 429 response. | 5 | -| MaxCalculator | `func(fiber.Ctx) int` | A function to calculate the max number of recent connections during `Expiration` seconds before sending a 429 response. | A function which returns the cfg.Max | +| MaxFunc | `func(fiber.Ctx) int` | A function to calculate the max number of recent connections during `Expiration` seconds before sending a 429 response. | A function which returns the cfg.Max | | KeyGenerator | `func(fiber.Ctx) string` | KeyGenerator allows you to generate custom keys, by default c.IP() is used. | A function using c.IP() as the default | | Expiration | `time.Duration` | Expiration is the time on how long to keep records of requests in memory. | 1 * time.Minute | | LimitReached | `fiber.Handler` | LimitReached is called when a request hits the limit. | A function sending 429 response | @@ -120,7 +120,7 @@ A custom store can be used if it implements the `Storage` interface - more detai ```go var ConfigDefault = Config{ Max: 5, - MaxCalculator: func(c fiber.Ctx) int { + MaxFunc: func(c fiber.Ctx) int { return 5 }, Expiration: 1 * time.Minute,