diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-01-12 01:57:30 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-01-20 02:36:34 +0300 |
commit | a9388ec5a852a55ee853ee1536996ebdd2514563 (patch) | |
tree | 55954bb830f9d2df6b6dff67befac83b73c2451d | |
parent | caaa4065b1d72257ad807a26be299d7fe7a1141b (diff) |
lint: solve internal/vfs/serving linter issues
-rw-r--r-- | internal/vfs/serving/main_test.go | 6 | ||||
-rw-r--r-- | internal/vfs/serving/serving.go | 12 | ||||
-rw-r--r-- | internal/vfs/serving/serving_test.go | 16 |
3 files changed, 8 insertions, 26 deletions
diff --git a/internal/vfs/serving/main_test.go b/internal/vfs/serving/main_test.go index 56babdc8..c0c2c29f 100644 --- a/internal/vfs/serving/main_test.go +++ b/internal/vfs/serving/main_test.go @@ -2,13 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//nolint package serving_test import ( "fmt" - "io" - "log" "net/http" "os" "runtime" @@ -18,8 +15,6 @@ import ( "time" ) -var quietLog = log.New(io.Discard, "", 0) - func TestMain(m *testing.M) { v := m.Run() if v == 0 && goroutineLeaked() { @@ -28,6 +23,7 @@ func TestMain(m *testing.M) { os.Exit(v) } +// nolint: gocyclo // this is vendored code func interestingGoroutines() (gs []string) { buf := make([]byte, 2<<20) buf = buf[:runtime.Stack(buf, true)] diff --git a/internal/vfs/serving/serving.go b/internal/vfs/serving/serving.go index 6da2c6ed..6f45e1d5 100644 --- a/internal/vfs/serving/serving.go +++ b/internal/vfs/serving/serving.go @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//nolint package serving import ( @@ -50,7 +49,7 @@ func serveContent(w http.ResponseWriter, r *http.Request, modtime time.Time, con w.WriteHeader(code) - if r.Method != "HEAD" { + if r.Method != http.MethodHead { io.Copy(w, content) } } @@ -185,7 +184,7 @@ func checkIfNoneMatch(w http.ResponseWriter, r *http.Request) condResult { } func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult { - if r.Method != "GET" && r.Method != "HEAD" { + if r.Method != http.MethodGet && r.Method != http.MethodHead { return condNone } ims := r.Header.Get("If-Modified-Since") @@ -247,13 +246,12 @@ func checkPreconditions(w http.ResponseWriter, r *http.Request, modtime time.Tim } switch checkIfNoneMatch(w, r) { case condFalse: - if r.Method == "GET" || r.Method == "HEAD" { + if r.Method == http.MethodGet || r.Method == http.MethodHead { writeNotModified(w) return true - } else { - w.WriteHeader(http.StatusPreconditionFailed) - return true } + w.WriteHeader(http.StatusPreconditionFailed) + return true case condNone: if checkIfModifiedSince(r, modtime) == condFalse { writeNotModified(w) diff --git a/internal/vfs/serving/serving_test.go b/internal/vfs/serving/serving_test.go index 01ce60fc..f7bfc2e9 100644 --- a/internal/vfs/serving/serving_test.go +++ b/internal/vfs/serving/serving_test.go @@ -2,15 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//nolint package serving_test import ( "io" - "io/fs" "net/http" "net/http/httptest" - "os" "strings" "testing" "time" @@ -25,6 +22,7 @@ var ( lastMod = time.Now() ) +// nolint: gocyclo // this is vendored code func TestServeContent(t *testing.T) { defer afterTest(t) type serveParam struct { @@ -218,7 +216,7 @@ func TestServeContent(t *testing.T) { }, } for testName, tt := range tests { - for _, method := range []string{"GET", "HEAD"} { + for _, method := range []string{http.MethodGet, http.MethodHead} { servec <- serveParam{ file: tt.file, modtime: tt.modtime, @@ -256,8 +254,6 @@ func TestServeContent(t *testing.T) { } } -type panicOnSeek struct{ io.ReadSeeker } - func Test_scanETag(t *testing.T) { tests := []struct { in string @@ -280,11 +276,3 @@ func Test_scanETag(t *testing.T) { } } } - -func mustStat(t *testing.T, fileName string) fs.FileInfo { - fi, err := os.Stat(fileName) - if err != nil { - t.Fatal(err) - } - return fi -} |