Skip to content

Commit 2ae8eb8

Browse files
committed
refactor: rename MaxCalculator to MaxFunc
1 parent fd3ce6d commit 2ae8eb8

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

middleware/limiter/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Config struct {
2323
// Default: func(c fiber.Ctx) int {
2424
// return c.Max
2525
// }
26-
MaxCalculator func(c fiber.Ctx) int
26+
MaxFunc func(c fiber.Ctx) int
2727

2828
// KeyGenerator allows you to generate custom keys, by default c.IP() is used
2929
//
@@ -109,8 +109,8 @@ func configDefault(config ...Config) Config {
109109
if cfg.LimiterMiddleware == nil {
110110
cfg.LimiterMiddleware = ConfigDefault.LimiterMiddleware
111111
}
112-
if cfg.MaxCalculator == nil {
113-
cfg.MaxCalculator = func(_ fiber.Ctx) int {
112+
if cfg.MaxFunc == nil {
113+
cfg.MaxFunc = func(_ fiber.Ctx) int {
114114
return cfg.Max
115115
}
116116
}

middleware/limiter/limiter_fixed.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (FixedWindow) New(cfg Config) fiber.Handler {
2727
// Return new handler
2828
return func(c fiber.Ctx) error {
2929
// Generate max from generator, if no generator was provided the default value returned is 5
30-
max := cfg.MaxCalculator(c)
30+
max := cfg.MaxFunc(c)
3131

3232
// Don't execute middleware if Next returns true or if the max is 0
3333
if (cfg.Next != nil && cfg.Next(c)) || max == 0 {

middleware/limiter/limiter_sliding.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (SlidingWindow) New(cfg Config) fiber.Handler {
2828
// Return new handler
2929
return func(c fiber.Ctx) error {
3030
// Generate max from generator, if no generator was provided the default value returned is 5
31-
max := cfg.MaxCalculator(c)
31+
max := cfg.MaxFunc(c)
3232

3333
// Don't execute middleware if Next returns true or if the max is 0
3434
if (cfg.Next != nil && cfg.Next(c)) || max == 0 {

middleware/limiter/limiter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Test_Limiter_With_Max_Calculator_With_Zero(t *testing.T) {
2020
app := fiber.New()
2121

2222
app.Use(New(Config{
23-
MaxCalculator: func(_ fiber.Ctx) int {
23+
MaxFunc: func(_ fiber.Ctx) int {
2424
return 0
2525
},
2626
Expiration: 2 * time.Second,
@@ -61,7 +61,7 @@ func Test_Limiter_With_Max_Calculator(t *testing.T) {
6161
max := 10
6262

6363
app.Use(New(Config{
64-
MaxCalculator: func(_ fiber.Ctx) int {
64+
MaxFunc: func(_ fiber.Ctx) int {
6565
return max
6666
},
6767
Expiration: 2 * time.Second,

0 commit comments

Comments
 (0)