From da073739d0f0adb52c8bceb4242ebc60e0f8444b Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Wed, 8 May 2024 05:40:43 +0200 Subject: [PATCH] update GitHub actions, fix code according to golancilint latest version (#108) --- .github/workflows/ci.yml | 15 +++++++-------- .golangci.yml | 6 +----- tollbooth_bug_report_test.go | 12 ++++++------ tollbooth_test.go | 8 ++++---- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc32917..f26c51b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,21 +12,20 @@ jobs: steps: - name: set up go 1.19 - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: - go-version: 1.19 + go-version: "1.19" id: go - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: build and test run: | go test -timeout=60s -race go build -race - - name: install golangci-lint - run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.45.2 - - - name: run golangci-lint - run: $GITHUB_WORKSPACE/golangci-lint run --out-format=github-actions + - name: golangci-lint + uses: golangci/golangci-lint-action@v4 + with: + version: latest diff --git a/.golangci.yml b/.golangci.yml index 880786a..5d0a4b6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,21 +1,17 @@ linters: enable: - - megacheck - revive - govet - unconvert - megacheck - - structcheck - gas - gocyclo - dupl - misspell - unparam - - varcheck - - deadcode + - unused - typecheck - ineffassign - - varcheck - stylecheck - gochecknoinits - exportloopref diff --git a/tollbooth_bug_report_test.go b/tollbooth_bug_report_test.go index 4ab584e..9c323d8 100644 --- a/tollbooth_bug_report_test.go +++ b/tollbooth_bug_report_test.go @@ -23,9 +23,9 @@ func Test_Issue48_RequestTerminatedEvenOnLowVolumeOnSameIP(t *testing.T) { lmt.SetMethods([]string{"GET"}) limitReachedCounter := 0 - lmt.SetOnLimitReached(func(w http.ResponseWriter, r *http.Request) { limitReachedCounter++ }) + lmt.SetOnLimitReached(func(http.ResponseWriter, *http.Request) { limitReachedCounter++ }) - handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte(`hello world`)) })) @@ -74,7 +74,7 @@ func Test_Issue66_CustomRateLimitByHeaderValues(t *testing.T) { customerID1 := "1234" customerID2 := "5678" - h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}) + h := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}) h, allocationLimiter := issue66RateLimiter(h, []string{customerID1, customerID2}) testServer := httptest.NewServer(h) @@ -145,7 +145,7 @@ func Test_Issue91_BrokenSetMethod_DontBlockGet(t *testing.T) { // ------------------------------------------------------------------- - handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte(`hello world`)) })) @@ -174,7 +174,7 @@ func Test_Issue91_BrokenSetMethod_BlockPost(t *testing.T) { lmt.SetMethods([]string{"POST"}) limitReachedCounter := 0 - lmt.SetOnLimitReached(func(w http.ResponseWriter, r *http.Request) { + lmt.SetOnLimitReached(func(http.ResponseWriter, *http.Request) { limitReachedCounter++ }) @@ -185,7 +185,7 @@ func Test_Issue91_BrokenSetMethod_BlockPost(t *testing.T) { // ------------------------------------------------------------------- - handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte(`hello world`)) })) diff --git a/tollbooth_test.go b/tollbooth_test.go index 25d197d..9d3f69c 100644 --- a/tollbooth_test.go +++ b/tollbooth_test.go @@ -337,9 +337,9 @@ func TestLimitHandler(t *testing.T) { lmt.SetMethods([]string{"POST"}) counter := 0 - lmt.SetOnLimitReached(func(w http.ResponseWriter, r *http.Request) { counter++ }) + lmt.SetOnLimitReached(func(http.ResponseWriter, *http.Request) { counter++ }) - handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte(`hello world`)) })) @@ -411,14 +411,14 @@ func TestOverrideForResponseWriter(t *testing.T) { lmt.SetOverrideDefaultResponseWriter(true) counter := 0 - lmt.SetOnLimitReached(func(w http.ResponseWriter, r *http.Request) { + lmt.SetOnLimitReached(func(w http.ResponseWriter, _ *http.Request) { w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusNotAcceptable) w.Write([]byte("rejecting the large amount of requests")) counter++ }) - handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + handler := LimitHandler(lmt, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte(`hello world`)) }))