Skip to content

Commit

Permalink
Fix golanci-lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gaby committed Aug 14, 2024
1 parent 8fd116d commit 05ac0d0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions middleware/limiter/limiter_fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func (FixedWindow) New(cfg Config) fiber.Handler {

// Return new handler
return func(c fiber.Ctx) error {
// Generate max_requests from generator, if no generator was provided the default value returned is 5
max_requests := cfg.MaxFunc(c)
// Generate maxRequests from generator, if no generator was provided the default value returned is 5
maxRequests := 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_requests == 0 {
if (cfg.Next != nil && cfg.Next(c)) || maxRequests == 0 {
return c.Next()
}

Expand Down Expand Up @@ -62,7 +62,7 @@ func (FixedWindow) New(cfg Config) fiber.Handler {
resetInSec := e.exp - ts

// Set how many hits we have left
remaining := max_requests - e.currHits
remaining := maxRequests - e.currHits

// Update storage
manager.set(key, e, cfg.Expiration)
Expand Down Expand Up @@ -98,7 +98,7 @@ func (FixedWindow) New(cfg Config) fiber.Handler {
}

// We can continue, update RateLimit headers
c.Set(xRateLimitLimit, strconv.Itoa(max_requests))
c.Set(xRateLimitLimit, strconv.Itoa(maxRequests))
c.Set(xRateLimitRemaining, strconv.Itoa(remaining))
c.Set(xRateLimitReset, strconv.FormatUint(resetInSec, 10))

Expand Down
8 changes: 4 additions & 4 deletions middleware/limiter/limiter_sliding.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (SlidingWindow) New(cfg Config) fiber.Handler {

// Return new handler
return func(c fiber.Ctx) error {
// Generate max_requests from generator, if no generator was provided the default value returned is 5
max_requests := cfg.MaxFunc(c)
// Generate maxRequests from generator, if no generator was provided the default value returned is 5
maxRequests := 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_requests == 0 {
if (cfg.Next != nil && cfg.Next(c)) || maxRequests == 0 {
return c.Next()
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func (SlidingWindow) New(cfg Config) fiber.Handler {
}

// We can continue, update RateLimit headers
c.Set(xRateLimitLimit, strconv.Itoa(max_requests))
c.Set(xRateLimitLimit, strconv.Itoa(maxRequests))
c.Set(xRateLimitRemaining, strconv.Itoa(remaining))
c.Set(xRateLimitReset, strconv.FormatUint(resetInSec, 10))

Expand Down
6 changes: 3 additions & 3 deletions middleware/limiter/limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func Test_Limiter_With_Max_Func_With_Zero(t *testing.T) {
func Test_Limiter_With_Max_Func(t *testing.T) {
t.Parallel()
app := fiber.New()
mas_requests := 10
maxRequests := 10

app.Use(New(Config{
MaxFunc: func(_ fiber.Ctx) int {
return mas_requests
return maxRequests
},
Expiration: 2 * time.Second,
Storage: memory.New(),
Expand All @@ -113,7 +113,7 @@ func Test_Limiter_With_Max_Func(t *testing.T) {

var wg sync.WaitGroup

for i := 0; i <= mas_requests-1; i++ {
for i := 0; i <= maxRequests-1; i++ {
wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()
Expand Down
6 changes: 3 additions & 3 deletions prefork.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func (app *App) prefork(addr string, tlsConfig *tls.Config, cfg ListenConfig) er
pid int
}
// create variables
max_procs := runtime.GOMAXPROCS(0)
maxProcs := runtime.GOMAXPROCS(0)
childs := make(map[int]*exec.Cmd)
channel := make(chan child, max_procs)
channel := make(chan child, maxProcs)

// kill child procs when master exits
defer func() {
Expand All @@ -95,7 +95,7 @@ func (app *App) prefork(addr string, tlsConfig *tls.Config, cfg ListenConfig) er
var pids []string

// launch child procs
for i := 0; i < max_procs; i++ {
for i := 0; i < maxProcs; i++ {
cmd := exec.Command(os.Args[0], os.Args[1:]...) //nolint:gosec // It's fine to launch the same process again
if testPreforkMaster {
// When test prefork master,
Expand Down

0 comments on commit 05ac0d0

Please sign in to comment.