Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add support for go1.23 and golangci-lint v1.60.1 #3101

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix golanci-lint issues
  • Loading branch information
gaby committed Aug 14, 2024
commit 8fd116d93d63c9ea8cf9ce0f0c82b75443f9e5e8
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
go-version: [1.22.x, 1.23.x]
platform: [ubuntu-latest, windows-latest, macos-latest, macos-14]
platform: [ubuntu-latest, windows-latest, macos-latest, macos-13]
runs-on: ${{ matrix.platform }}
steps:
- name: Fetch Repository
Expand Down
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 @@

// 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.MaxFunc(c)
// Generate max_requests from generator, if no generator was provided the default value returned is 5
max_requests := cfg.MaxFunc(c)

Check failure on line 30 in middleware/limiter/limiter_fixed.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var max_requests should be maxRequests (revive)

Check failure on line 30 in middleware/limiter/limiter_fixed.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: should not use underscores in Go names; var max_requests should be maxRequests (stylecheck)
gaby marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down Expand Up @@ -62,7 +62,7 @@
resetInSec := e.exp - ts

// Set how many hits we have left
remaining := max - e.currHits
remaining := max_requests - e.currHits
gaby marked this conversation as resolved.
Show resolved Hide resolved

// Update storage
manager.set(key, e, cfg.Expiration)
Expand Down Expand Up @@ -98,7 +98,7 @@
}

// We can continue, update RateLimit headers
c.Set(xRateLimitLimit, strconv.Itoa(max))
c.Set(xRateLimitLimit, strconv.Itoa(max_requests))
gaby marked this conversation as resolved.
Show resolved Hide resolved
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 @@

// 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.MaxFunc(c)
// Generate max_requests from generator, if no generator was provided the default value returned is 5
max_requests := cfg.MaxFunc(c)

Check failure on line 31 in middleware/limiter/limiter_sliding.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var max_requests should be maxRequests (revive)

Check failure on line 31 in middleware/limiter/limiter_sliding.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: should not use underscores in Go names; var max_requests should be maxRequests (stylecheck)
gaby marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down Expand Up @@ -129,7 +129,7 @@
}

// We can continue, update RateLimit headers
c.Set(xRateLimitLimit, strconv.Itoa(max))
c.Set(xRateLimitLimit, strconv.Itoa(max_requests))
gaby marked this conversation as resolved.
Show resolved Hide resolved
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(t *testing.T) {
t.Parallel()
app := fiber.New()
max := 10
mas_requests := 10

Check failure on line 100 in middleware/limiter/limiter_test.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var mas_requests should be masRequests (revive)

Check failure on line 100 in middleware/limiter/limiter_test.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: should not use underscores in Go names; var mas_requests should be masRequests (stylecheck)
gaby marked this conversation as resolved.
Show resolved Hide resolved

app.Use(New(Config{
MaxFunc: func(_ fiber.Ctx) int {
return max
return mas_requests
gaby marked this conversation as resolved.
Show resolved Hide resolved
},
Expiration: 2 * time.Second,
Storage: memory.New(),
Expand All @@ -113,7 +113,7 @@

var wg sync.WaitGroup

for i := 0; i <= max-1; i++ {
for i := 0; i <= mas_requests-1; i++ {
gaby marked this conversation as resolved.
Show resolved Hide resolved
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 @@
pid int
}
// create variables
max := runtime.GOMAXPROCS(0)
max_procs := runtime.GOMAXPROCS(0)

Check failure on line 79 in prefork.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var max_procs should be maxProcs (revive)

Check failure on line 79 in prefork.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: should not use underscores in Go names; var max_procs should be maxProcs (stylecheck)
gaby marked this conversation as resolved.
Show resolved Hide resolved
childs := make(map[int]*exec.Cmd)
channel := make(chan child, max)
channel := make(chan child, max_procs)
gaby marked this conversation as resolved.
Show resolved Hide resolved

// kill child procs when master exits
defer func() {
Expand All @@ -95,7 +95,7 @@
var pids []string

// launch child procs
for i := 0; i < max; i++ {
for i := 0; i < max_procs; i++ {
gaby marked this conversation as resolved.
Show resolved Hide resolved
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
Loading