Skip to content

Commit

Permalink
refactor: rename MaxCalculator to MaxFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3skyw4lker committed Jul 22, 2024
1 parent fd3ce6d commit 2ae8eb8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions middleware/limiter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
// Default: func(c fiber.Ctx) int {
// return c.Max
// }
MaxCalculator func(c fiber.Ctx) int
MaxFunc func(c fiber.Ctx) int

// KeyGenerator allows you to generate custom keys, by default c.IP() is used
//
Expand Down Expand Up @@ -109,8 +109,8 @@ func configDefault(config ...Config) Config {
if cfg.LimiterMiddleware == nil {
cfg.LimiterMiddleware = ConfigDefault.LimiterMiddleware
}
if cfg.MaxCalculator == nil {
cfg.MaxCalculator = func(_ fiber.Ctx) int {
if cfg.MaxFunc == nil {
cfg.MaxFunc = func(_ fiber.Ctx) int {
return cfg.Max
}
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/limiter/limiter_fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (FixedWindow) New(cfg Config) fiber.Handler {
// Return new handler
return func(c fiber.Ctx) error {
// Generate max from generator, if no generator was provided the default value returned is 5
max := cfg.MaxCalculator(c)
max := cfg.MaxFunc(c)

// Don't execute middleware if Next returns true or if the max is 0
if (cfg.Next != nil && cfg.Next(c)) || max == 0 {
Expand Down
2 changes: 1 addition & 1 deletion middleware/limiter/limiter_sliding.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (SlidingWindow) New(cfg Config) fiber.Handler {
// Return new handler
return func(c fiber.Ctx) error {
// Generate max from generator, if no generator was provided the default value returned is 5
max := cfg.MaxCalculator(c)
max := cfg.MaxFunc(c)

// Don't execute middleware if Next returns true or if the max is 0
if (cfg.Next != nil && cfg.Next(c)) || max == 0 {
Expand Down
4 changes: 2 additions & 2 deletions middleware/limiter/limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_Limiter_With_Max_Calculator_With_Zero(t *testing.T) {
app := fiber.New()

app.Use(New(Config{
MaxCalculator: func(_ fiber.Ctx) int {
MaxFunc: func(_ fiber.Ctx) int {
return 0
},
Expiration: 2 * time.Second,
Expand Down Expand Up @@ -61,7 +61,7 @@ func Test_Limiter_With_Max_Calculator(t *testing.T) {
max := 10

app.Use(New(Config{
MaxCalculator: func(_ fiber.Ctx) int {
MaxFunc: func(_ fiber.Ctx) int {
return max
},
Expiration: 2 * time.Second,
Expand Down

0 comments on commit 2ae8eb8

Please sign in to comment.