Skip to content

Commit a99fa6d

Browse files
committed
chore(lint): add golang lint config
Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent f6388b3 commit a99fa6d

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

.golangci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
linters:
2+
enable-all: false
3+
disable-all: true
4+
fast: false
5+
enable:
6+
- bodyclose
7+
- deadcode
8+
- depguard
9+
- dogsled
10+
- dupl
11+
- errcheck
12+
- exportloopref
13+
- exhaustive
14+
- gochecknoinits
15+
- goconst
16+
- gocritic
17+
- gocyclo
18+
- gofmt
19+
- goimports
20+
- goprintffuncname
21+
- gosec
22+
- gosimple
23+
- govet
24+
- ineffassign
25+
- lll
26+
- misspell
27+
- nakedret
28+
- noctx
29+
- nolintlint
30+
- rowserrcheck
31+
- staticcheck
32+
- structcheck
33+
- stylecheck
34+
- typecheck
35+
- unconvert
36+
- unparam
37+
- unused
38+
- varcheck
39+
- whitespace
40+
- gofumpt
41+
42+
run:
43+
timeout: 3m

serve_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package static
22

33
import (
4+
"context"
45
"io/ioutil"
56
"net/http"
67
"net/http/httptest"
@@ -13,8 +14,14 @@ import (
1314
"github.com/stretchr/testify/assert"
1415
)
1516

17+
<<<<<<< HEAD:serve_test.go
1618
func PerformRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
1719
req, _ := http.NewRequest(method, path, nil)
20+
=======
21+
// nolint:unparam
22+
func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
23+
req, _ := http.NewRequestWithContext(context.Background(), method, path, nil)
24+
>>>>>>> 7756450 (chore(lint): add golang lint config):static_test.go
1825
w := httptest.NewRecorder()
1926
r.ServeHTTP(w, req)
2027
return w
@@ -36,13 +43,13 @@ func TestEmptyDirectory(t *testing.T) {
3643
router := gin.New()
3744
router.Use(ServeRoot("/", dir))
3845
router.GET("/", func(c *gin.Context) {
39-
c.String(200, "index")
46+
c.String(http.StatusOK, "index")
4047
})
4148
router.GET("/a", func(c *gin.Context) {
42-
c.String(200, "a")
49+
c.String(http.StatusOK, "a")
4350
})
4451
router.GET("/"+filename, func(c *gin.Context) {
45-
c.String(200, "this is not printed")
52+
c.String(http.StatusOK, "this is not printed")
4653
})
4754
w := PerformRequest(router, "GET", "/")
4855
assert.Equal(t, w.Code, 200)
@@ -62,7 +69,7 @@ func TestEmptyDirectory(t *testing.T) {
6269
router2 := gin.New()
6370
router2.Use(ServeRoot("/static", dir))
6471
router2.GET("/"+filename, func(c *gin.Context) {
65-
c.String(200, "this is printed")
72+
c.String(http.StatusOK, "this is printed")
6673
})
6774

6875
w = PerformRequest(router2, "GET", "/")
@@ -71,7 +78,7 @@ func TestEmptyDirectory(t *testing.T) {
7178
w = PerformRequest(router2, "GET", "/static")
7279
assert.Equal(t, w.Code, 404)
7380
router2.GET("/static", func(c *gin.Context) {
74-
c.String(200, "index")
81+
c.String(http.StatusOK, "index")
7582
})
7683

7784
w = PerformRequest(router2, "GET", "/static")

0 commit comments

Comments
 (0)