chore(lint): add golang lint config
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
f6388b32d6
commit
a99fa6d897
|
@ -0,0 +1,43 @@
|
||||||
|
linters:
|
||||||
|
enable-all: false
|
||||||
|
disable-all: true
|
||||||
|
fast: false
|
||||||
|
enable:
|
||||||
|
- bodyclose
|
||||||
|
- deadcode
|
||||||
|
- depguard
|
||||||
|
- dogsled
|
||||||
|
- dupl
|
||||||
|
- errcheck
|
||||||
|
- exportloopref
|
||||||
|
- exhaustive
|
||||||
|
- gochecknoinits
|
||||||
|
- goconst
|
||||||
|
- gocritic
|
||||||
|
- gocyclo
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- goprintffuncname
|
||||||
|
- gosec
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- lll
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- noctx
|
||||||
|
- nolintlint
|
||||||
|
- rowserrcheck
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- stylecheck
|
||||||
|
- typecheck
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
- whitespace
|
||||||
|
- gofumpt
|
||||||
|
|
||||||
|
run:
|
||||||
|
timeout: 3m
|
|
@ -1,6 +1,7 @@
|
||||||
package static
|
package static
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -13,8 +14,14 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
<<<<<<< HEAD:serve_test.go
|
||||||
func PerformRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
|
func PerformRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
|
||||||
req, _ := http.NewRequest(method, path, nil)
|
req, _ := http.NewRequest(method, path, nil)
|
||||||
|
=======
|
||||||
|
// nolint:unparam
|
||||||
|
func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
|
||||||
|
req, _ := http.NewRequestWithContext(context.Background(), method, path, nil)
|
||||||
|
>>>>>>> 7756450 (chore(lint): add golang lint config):static_test.go
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r.ServeHTTP(w, req)
|
r.ServeHTTP(w, req)
|
||||||
return w
|
return w
|
||||||
|
@ -36,13 +43,13 @@ func TestEmptyDirectory(t *testing.T) {
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.Use(ServeRoot("/", dir))
|
router.Use(ServeRoot("/", dir))
|
||||||
router.GET("/", func(c *gin.Context) {
|
router.GET("/", func(c *gin.Context) {
|
||||||
c.String(200, "index")
|
c.String(http.StatusOK, "index")
|
||||||
})
|
})
|
||||||
router.GET("/a", func(c *gin.Context) {
|
router.GET("/a", func(c *gin.Context) {
|
||||||
c.String(200, "a")
|
c.String(http.StatusOK, "a")
|
||||||
})
|
})
|
||||||
router.GET("/"+filename, func(c *gin.Context) {
|
router.GET("/"+filename, func(c *gin.Context) {
|
||||||
c.String(200, "this is not printed")
|
c.String(http.StatusOK, "this is not printed")
|
||||||
})
|
})
|
||||||
w := PerformRequest(router, "GET", "/")
|
w := PerformRequest(router, "GET", "/")
|
||||||
assert.Equal(t, w.Code, 200)
|
assert.Equal(t, w.Code, 200)
|
||||||
|
@ -62,7 +69,7 @@ func TestEmptyDirectory(t *testing.T) {
|
||||||
router2 := gin.New()
|
router2 := gin.New()
|
||||||
router2.Use(ServeRoot("/static", dir))
|
router2.Use(ServeRoot("/static", dir))
|
||||||
router2.GET("/"+filename, func(c *gin.Context) {
|
router2.GET("/"+filename, func(c *gin.Context) {
|
||||||
c.String(200, "this is printed")
|
c.String(http.StatusOK, "this is printed")
|
||||||
})
|
})
|
||||||
|
|
||||||
w = PerformRequest(router2, "GET", "/")
|
w = PerformRequest(router2, "GET", "/")
|
||||||
|
@ -71,7 +78,7 @@ func TestEmptyDirectory(t *testing.T) {
|
||||||
w = PerformRequest(router2, "GET", "/static")
|
w = PerformRequest(router2, "GET", "/static")
|
||||||
assert.Equal(t, w.Code, 404)
|
assert.Equal(t, w.Code, 404)
|
||||||
router2.GET("/static", func(c *gin.Context) {
|
router2.GET("/static", func(c *gin.Context) {
|
||||||
c.String(200, "index")
|
c.String(http.StatusOK, "index")
|
||||||
})
|
})
|
||||||
|
|
||||||
w = PerformRequest(router2, "GET", "/static")
|
w = PerformRequest(router2, "GET", "/static")
|
||||||
|
|
Loading…
Reference in New Issue