Skip to content

Commit 005eb18

Browse files
committed
chore: update codebase to comply with new Go linter rules and standards
- Update golangci-lint-action usage to v7 and set version to v2.0 in GitHub workflow - Add version field and replace linters settings in `.golangci.yml` - Update linter exclusions and presets, adjust paths and formatters configurations in `.golangci.yml` - Replace `ioutil` package with `io` package for `ReadAll` and `NopCloser` in multiple files to accommodate changes in Go's standard library Signed-off-by: appleboy <[email protected]>
1 parent f7e055f commit 005eb18

File tree

4 files changed

+42
-31
lines changed

4 files changed

+42
-31
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
with:
2121
go-version-file: "go.mod"
2222
- name: Setup golangci-lint
23-
uses: golangci/golangci-lint-action@v6
23+
uses: golangci/golangci-lint-action@v7
2424
with:
25+
version: v2.0
2526
args: --verbose
2627
test:
2728
strategy:

.golangci.yml

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1+
version: "2"
12
linters:
2-
enable-all: false
3-
disable-all: true
4-
fast: false
3+
default: none
54
enable:
65
- bodyclose
76
- dogsled
87
- dupl
98
- errcheck
10-
- exportloopref
119
- exhaustive
1210
- gochecknoinits
1311
- goconst
1412
- gocritic
1513
- gocyclo
16-
- gofmt
17-
- goimports
1814
- goprintffuncname
1915
- gosec
20-
- gosimple
2116
- govet
2217
- ineffassign
2318
- lll
@@ -27,25 +22,40 @@ linters:
2722
- nolintlint
2823
- rowserrcheck
2924
- staticcheck
30-
- stylecheck
31-
- typecheck
3225
- unconvert
3326
- unparam
3427
- unused
3528
- whitespace
29+
exclusions:
30+
generated: lax
31+
presets:
32+
- comments
33+
- common-false-positives
34+
- legacy
35+
- std-error-handling
36+
rules:
37+
- linters:
38+
- bodyclose
39+
- unparam
40+
path: authenticator_test.go
41+
- linters:
42+
- lll
43+
path: parser_test.go
44+
- linters:
45+
- lll
46+
path: signatureheader_test.go
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$
51+
formatters:
52+
enable:
53+
- gofmt
3654
- gofumpt
37-
38-
issues:
39-
exclude-rules:
40-
- path: authenticator_test.go
41-
linters:
42-
- bodyclose
43-
- unparam
44-
- path: parser_test.go
45-
linters:
46-
- lll
47-
- path: signatureheader_test.go
48-
linters:
49-
- lll
50-
run:
51-
timeout: 3m
55+
- goimports
56+
exclusions:
57+
generated: lax
58+
paths:
59+
- third_party$
60+
- builtin$
61+
- examples$

authenticator_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package httpsign
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"strings"
@@ -250,7 +250,7 @@ func TestHttpValidRequestBody(t *testing.T) {
250250
r.ServeHTTP(w, req)
251251

252252
assert.Equal(t, http.StatusOK, w.Code)
253-
body, err := ioutil.ReadAll(w.Result().Body)
253+
body, err := io.ReadAll(w.Result().Body)
254254
assert.NoError(t, err)
255255
assert.Equal(t, body, []byte(sampleBodyContent))
256256
}
@@ -275,7 +275,7 @@ func TestHttpValidRequestHost(t *testing.T) {
275275
r.ServeHTTP(w, req)
276276

277277
assert.Equal(t, http.StatusOK, w.Code)
278-
body, err := ioutil.ReadAll(w.Result().Body)
278+
body, err := io.ReadAll(w.Result().Body)
279279
assert.NoError(t, err)
280280
assert.Equal(t, body, []byte(sampleBodyContent))
281281
}

validator/digestvalidate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/base64"
77
"errors"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111

1212
"github.com/gin-gonic/gin"
@@ -46,11 +46,11 @@ func calculateDigest(r *http.Request) (string, error) {
4646
return "", nil
4747
}
4848
// TODO: Read body using buffer to prevent using too much memory
49-
body, err := ioutil.ReadAll(r.Body)
49+
body, err := io.ReadAll(r.Body)
5050
if err != nil {
5151
return "", err
5252
}
53-
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
53+
r.Body = io.NopCloser(bytes.NewBuffer(body))
5454
h := sha256.New()
5555
h.Write(body)
5656
if err != nil {

0 commit comments

Comments
 (0)