diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c5f9e4a..33dce5d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,5 +6,9 @@ jobs: lint: runs-on: ubuntu-latest steps: + - name: Checkout code + uses: actions/checkout@v2 - name: GolangCI-Lint Action - uses: actions-contrib/golangci-lint@v0.1.0 + uses: actions-contrib/golangci-lint@v1 + with: + golangci_lint_version: v1.28.3 diff --git a/allocation_test.go b/allocation_test.go index cdb4aaa..9d3d167 100644 --- a/allocation_test.go +++ b/allocation_test.go @@ -78,7 +78,7 @@ func TestAllocationURI(t *testing.T) { n := testing.AllocsPerRun(100, func() { u := AcquireURI() - u.Parse(nil, uri) + u.Parse(nil, uri) //nolint:errcheck ReleaseURI(u) }) diff --git a/args_test.go b/args_test.go index 83a1256..f6c62ae 100644 --- a/args_test.go +++ b/args_test.go @@ -336,8 +336,8 @@ func testCopyTo(t *testing.T, a *Args) { var b Args a.CopyTo(&b) - if !reflect.DeepEqual(*a, b) { //nolint:govet - t.Fatalf("ArgsCopyTo fail, a: \n%+v\nb: \n%+v\n", *a, b) //nolint:govet + if !reflect.DeepEqual(*a, b) { //nolint + t.Fatalf("ArgsCopyTo fail, a: \n%+v\nb: \n%+v\n", *a, b) //nolint } b.VisitAll(func(k, v []byte) { diff --git a/client.go b/client.go index 2a7f298..bef5e6a 100644 --- a/client.go +++ b/client.go @@ -915,7 +915,7 @@ func doRequestFollowRedirectsBuffer(req *Request, dst []byte, url string, c clie oldBody := bodyBuf.B bodyBuf.B = dst - statusCode, body, err = doRequestFollowRedirects(req, resp, url, defaultMaxRedirectsCount, c) + statusCode, _, err = doRequestFollowRedirects(req, resp, url, defaultMaxRedirectsCount, c) body = bodyBuf.B bodyBuf.B = oldBody diff --git a/client_test.go b/client_test.go index 3088181..bb04cef 100644 --- a/client_test.go +++ b/client_test.go @@ -84,7 +84,7 @@ func TestClientInvalidURI(t *testing.T) { atomic.AddInt64(&requests, 1) }, } - go s.Serve(ln) + go s.Serve(ln) //nolint:errcheck c := &Client{ Dial: func(addr string) (net.Conn, error) { return ln.Dial() @@ -113,10 +113,10 @@ func TestClientGetWithBody(t *testing.T) { s := &Server{ Handler: func(ctx *RequestCtx) { body := ctx.Request.Body() - ctx.Write(body) + ctx.Write(body) //nolint:errcheck }, } - go s.Serve(ln) + go s.Serve(ln) //nolint:errcheck c := &Client{ Dial: func(addr string) (net.Conn, error) { return ln.Dial() diff --git a/fasthttpadaptor/adaptor_test.go b/fasthttpadaptor/adaptor_test.go index 0cfeddd..f98d090 100644 --- a/fasthttpadaptor/adaptor_test.go +++ b/fasthttpadaptor/adaptor_test.go @@ -144,7 +144,7 @@ func setContextValueMiddleware(next fasthttp.RequestHandler, key string, value i func TestContentType(t *testing.T) { nethttpH := func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("")) + w.Write([]byte("")) //nolint:errcheck } fasthttpH := NewFastHTTPHandler(http.HandlerFunc(nethttpH)) diff --git a/fasthttputil/inmemory_listener_test.go b/fasthttputil/inmemory_listener_test.go index 5575ffe..9de59e1 100644 --- a/fasthttputil/inmemory_listener_test.go +++ b/fasthttputil/inmemory_listener_test.go @@ -21,29 +21,29 @@ func TestInmemoryListener(t *testing.T) { go func(n int) { conn, err := ln.Dial() if err != nil { - t.Fatalf("unexpected error: %s", err) + t.Errorf("unexpected error: %s", err) } defer conn.Close() req := fmt.Sprintf("request_%d", n) nn, err := conn.Write([]byte(req)) if err != nil { - t.Fatalf("unexpected error: %s", err) + t.Errorf("unexpected error: %s", err) } if nn != len(req) { - t.Fatalf("unexpected number of bytes written: %d. Expecting %d", nn, len(req)) + t.Errorf("unexpected number of bytes written: %d. Expecting %d", nn, len(req)) } buf := make([]byte, 30) nn, err = conn.Read(buf) if err != nil { - t.Fatalf("unexpected error: %s", err) + t.Errorf("unexpected error: %s", err) } buf = buf[:nn] resp := fmt.Sprintf("response_%d", n) if nn != len(resp) { - t.Fatalf("unexpected number of bytes read: %d. Expecting %d", nn, len(resp)) + t.Errorf("unexpected number of bytes read: %d. Expecting %d", nn, len(resp)) } if string(buf) != resp { - t.Fatalf("unexpected response %q. Expecting %q", buf, resp) + t.Errorf("unexpected response %q. Expecting %q", buf, resp) } ch <- struct{}{} }(i) @@ -61,19 +61,19 @@ func TestInmemoryListener(t *testing.T) { buf := make([]byte, 30) n, err := conn.Read(buf) if err != nil { - t.Fatalf("unexpected error: %s", err) + t.Errorf("unexpected error: %s", err) } buf = buf[:n] if !bytes.HasPrefix(buf, []byte("request_")) { - t.Fatalf("unexpected request prefix %q. Expecting %q", buf, "request_") + t.Errorf("unexpected request prefix %q. Expecting %q", buf, "request_") } resp := fmt.Sprintf("response_%s", buf[len("request_"):]) n, err = conn.Write([]byte(resp)) if err != nil { - t.Fatalf("unexpected error: %s", err) + t.Errorf("unexpected error: %s", err) } if n != len(resp) { - t.Fatalf("unexpected number of bytes written: %d. Expecting %d", n, len(resp)) + t.Errorf("unexpected number of bytes written: %d. Expecting %d", n, len(resp)) } } }() @@ -129,7 +129,7 @@ func testInmemoryListenerHTTP(t *testing.T, f func(t *testing.T, client *http.Cl go func() { if err := server.Serve(ln); err != nil && err != http.ErrServerClosed { - t.Fatalf("unexpected error: %s", err) + t.Errorf("unexpected error: %s", err) } }() diff --git a/fasthttputil/inmemory_listener_timing_test.go b/fasthttputil/inmemory_listener_timing_test.go index a85f37f..af0ef62 100644 --- a/fasthttputil/inmemory_listener_timing_test.go +++ b/fasthttputil/inmemory_listener_timing_test.go @@ -143,7 +143,7 @@ func benchmarkExt(b *testing.B, h fasthttp.RequestHandler, bc *benchConfig) { serverLn = tls.NewListener(serverLn, serverTLSConfig) } if err := fasthttp.Serve(serverLn, h); err != nil { - b.Fatalf("unexpected error in server: %s", err) + b.Errorf("unexpected error in server: %s", err) } close(serverStopCh) }() diff --git a/http.go b/http.go index 28ba09d..e18e91f 100644 --- a/http.go +++ b/http.go @@ -725,7 +725,7 @@ func swapResponseBody(a, b *Response) { // URI returns request URI func (req *Request) URI() *URI { - req.parseURI() + req.parseURI() //nolint:errcheck return &req.uri } diff --git a/http_test.go b/http_test.go index 3173d2d..bcac9dc 100644 --- a/http_test.go +++ b/http_test.go @@ -21,7 +21,7 @@ func TestFragmentInURIRequest(t *testing.T) { req.SetRequestURI("https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#events") var b bytes.Buffer - req.WriteTo(&b) + req.WriteTo(&b) //nolint:errcheck got := b.String() expected := "GET /ee/user/project/integrations/webhooks.html HTTP/1.1\r\nHost: docs.gitlab.com\r\n\r\n" diff --git a/reuseport/reuseport_test.go b/reuseport/reuseport_test.go index a9b60ea..08722c3 100644 --- a/reuseport/reuseport_test.go +++ b/reuseport/reuseport_test.go @@ -66,7 +66,7 @@ func testNewListener(t *testing.T, network, addr string, serversCount, requestsC ch := make(chan struct{}) go func() { if resp, err = ioutil.ReadAll(c); err != nil { - t.Fatalf("%d. unexpected error when reading response: %s", i, err) + t.Errorf("%d. unexpected error when reading response: %s", i, err) } close(ch) }() diff --git a/server.go b/server.go index d4acd35..699b252 100644 --- a/server.go +++ b/server.go @@ -1575,7 +1575,10 @@ func (s *Server) ServeTLS(ln net.Listener, certFile, keyFile string) error { if s.tlsConfig == nil { return errNoCertOrKeyProvided } - s.tlsConfig.BuildNameToCertificate() + + // BuildNameToCertificate has been deprecated since 1.14. + // But since we also support older versions we'll keep this here. + s.tlsConfig.BuildNameToCertificate() //nolint:staticcheck return s.Serve( tls.NewListener(ln, s.tlsConfig), @@ -1596,7 +1599,10 @@ func (s *Server) ServeTLSEmbed(ln net.Listener, certData, keyData []byte) error if s.tlsConfig == nil { return errNoCertOrKeyProvided } - s.tlsConfig.BuildNameToCertificate() + + // BuildNameToCertificate has been deprecated since 1.14. + // But since we also support older versions we'll keep this here. + s.tlsConfig.BuildNameToCertificate() //nolint:staticcheck return s.Serve( tls.NewListener(ln, s.tlsConfig), diff --git a/server_test.go b/server_test.go index fba7598..e52114d 100644 --- a/server_test.go +++ b/server_test.go @@ -2293,7 +2293,7 @@ func TestRequestCtxNoHijackNoResponse(t *testing.T) { s := &Server{ Handler: func(ctx *RequestCtx) { - io.WriteString(ctx, "test") + io.WriteString(ctx, "test") //nolint:errcheck ctx.HijackSetNoResponse(true) }, } @@ -2319,7 +2319,7 @@ func TestRequestCtxNoHijackNoResponse(t *testing.T) { strings.NewReader(rw.w.String()), ) resp := AcquireResponse() - resp.Read(bf) + resp.Read(bf) //nolint:errcheck if got := string(resp.Body()); got != "test" { t.Errorf(`expected "test", got %q`, got) } diff --git a/uri_test.go b/uri_test.go index d41c067..0a59db5 100644 --- a/uri_test.go +++ b/uri_test.go @@ -56,7 +56,7 @@ func testURIAcquireRelease(t *testing.T) { host := fmt.Sprintf("host.%d.com", i*23) path := fmt.Sprintf("/foo/%d/bar", i*17) queryArgs := "?foo=bar&baz=aass" - u.Parse([]byte(host), []byte(path+queryArgs)) + u.Parse([]byte(host), []byte(path+queryArgs)) //nolint:errcheck if string(u.Host()) != host { t.Fatalf("unexpected host %q. Expecting %q", u.Host(), host) } @@ -133,7 +133,7 @@ func TestURIUpdate(t *testing.T) { func testURIUpdate(t *testing.T, base, update, result string) { var u URI - u.Parse(nil, []byte(base)) + u.Parse(nil, []byte(base)) //nolint:errcheck u.Update(update) s := u.String() if s != result { @@ -190,7 +190,7 @@ func TestURIPathNormalize(t *testing.T) { } func testURIPathNormalize(t *testing.T, u *URI, requestURI, expectedPath string) { - u.Parse(nil, []byte(requestURI)) + u.Parse(nil, []byte(requestURI)) //nolint:errcheck if string(u.Path()) != expectedPath { t.Fatalf("Unexpected path %q. Expected %q. requestURI=%q", u.Path(), expectedPath, requestURI) } @@ -201,7 +201,7 @@ func TestURINoNormalization(t *testing.T) { var u URI irregularPath := "/aaa%2Fbbb%2F%2E.%2Fxxx" - u.Parse(nil, []byte(irregularPath)) + u.Parse(nil, []byte(irregularPath)) //nolint:errcheck u.DisablePathNormalizing = true if string(u.RequestURI()) != irregularPath { t.Fatalf("Unexpected path %q. Expected %q.", u.Path(), irregularPath) @@ -250,7 +250,7 @@ func TestURIFullURI(t *testing.T) { // test with empty args and non-empty query string var u URI - u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq")) + u.Parse([]byte("google.com"), []byte("/foo?bar=baz&baraz#qqqq")) //nolint:errcheck uri := u.FullURI() expectedURI := "http://google.com/foo?bar=baz&baraz#qqqq" if string(uri) != expectedURI { @@ -287,7 +287,7 @@ func TestURIParseNilHost(t *testing.T) { func testURIParseScheme(t *testing.T, uri, expectedScheme, expectedHost, expectedRequestURI, expectedHash string) { var u URI - u.Parse(nil, []byte(uri)) + u.Parse(nil, []byte(uri)) //nolint:errcheck if string(u.Scheme()) != expectedScheme { t.Fatalf("Unexpected scheme %q. Expecting %q for uri %q", u.Scheme(), expectedScheme, uri) } @@ -361,7 +361,7 @@ func TestURIParse(t *testing.T) { func testURIParse(t *testing.T, u *URI, host, uri, expectedURI, expectedHost, expectedPath, expectedPathOriginal, expectedArgs, expectedHash string) { - u.Parse([]byte(host), []byte(uri)) + u.Parse([]byte(host), []byte(uri)) //nolint:errcheck if !bytes.Equal(u.FullURI(), []byte(expectedURI)) { t.Fatalf("Unexpected uri %q. Expected %q. host=%q, uri=%q", u.FullURI(), expectedURI, host, uri) diff --git a/uri_timing_test.go b/uri_timing_test.go index 44a1d29..1d2cdd4 100644 --- a/uri_timing_test.go +++ b/uri_timing_test.go @@ -27,7 +27,7 @@ func BenchmarkURIFullURI(b *testing.B) { b.RunParallel(func(pb *testing.PB) { var u URI - u.Parse(host, requestURI) + u.Parse(host, requestURI) //nolint:errcheck for pb.Next() { uri := u.FullURI() if len(uri) != uriLen { @@ -43,7 +43,7 @@ func benchmarkURIParse(b *testing.B, host, uri string) { b.RunParallel(func(pb *testing.PB) { var u URI for pb.Next() { - u.Parse(strHost, strURI) + u.Parse(strHost, strURI) //nolint:errcheck } }) }