From 3166afd835a00486c918f1d3149696855897c923 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Sat, 2 Mar 2024 17:19:05 +0200 Subject: Enable few gocritic checks; fix up issues (#1728) --- .golangci.yml | 4 ---- client_timing_test.go | 4 ++-- fs.go | 4 ++-- header.go | 4 ++-- http.go | 10 +++++----- http_test.go | 4 ++-- prefork/prefork.go | 3 ++- server.go | 2 +- status.go | 2 +- userdata.go | 2 +- 10 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 674e3ab..fb3861d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -77,12 +77,8 @@ linters-settings: - style disabled-checks: - deferInLoop - - httpNoBody - importShadow - - initClause - - paramTypeCombine - sloppyReassign - - typeUnparen - unnamedResult - whyNoLint diff --git a/client_timing_test.go b/client_timing_test.go index 416ad53..5e9a2f4 100644 --- a/client_timing_test.go +++ b/client_timing_test.go @@ -165,7 +165,7 @@ func BenchmarkNetHTTPClientDoFastServer(b *testing.B) { nn := uint32(0) b.RunParallel(func(pb *testing.PB) { - req, err := http.NewRequest(MethodGet, fmt.Sprintf("http://foobar%d.com/aaa/bbb", atomic.AddUint32(&nn, 1)), nil) + req, err := http.NewRequest(MethodGet, fmt.Sprintf("http://foobar%d.com/aaa/bbb", atomic.AddUint32(&nn, 1)), http.NoBody) if err != nil { b.Fatalf("unexpected error: %v", err) } @@ -550,7 +550,7 @@ func benchmarkNetHTTPClientEndToEndBigResponseInmemory(b *testing.B, parallelism url := "http://unused.host" + requestURI b.SetParallelism(parallelism) b.RunParallel(func(pb *testing.PB) { - req, err := http.NewRequest(MethodGet, url, nil) + req, err := http.NewRequest(MethodGet, url, http.NoBody) if err != nil { b.Fatalf("unexpected error: %v", err) } diff --git a/fs.go b/fs.go index 4f2bbbf..6793713 100644 --- a/fs.go +++ b/fs.go @@ -1350,7 +1350,7 @@ const ( fsMaxCompressibleFileSize = 8 * 1024 * 1024 ) -func (h *fsHandler) compressAndOpenFSFile(filePath string, fileEncoding string) (*fsFile, error) { +func (h *fsHandler) compressAndOpenFSFile(filePath, fileEncoding string) (*fsFile, error) { f, err := h.filesystem.Open(filePath) if err != nil { return nil, err @@ -1532,7 +1532,7 @@ func (h *fsHandler) newCompressedFSFileCache(f fs.File, fileInfo fs.FileInfo, fi return ff, nil } -func (h *fsHandler) newCompressedFSFile(filePath string, fileEncoding string) (*fsFile, error) { +func (h *fsHandler) newCompressedFSFile(filePath, fileEncoding string) (*fsFile, error) { f, err := h.filesystem.Open(filePath) if err != nil { return nil, fmt.Errorf("cannot open compressed file %q: %w", filePath, err) diff --git a/header.go b/header.go index c20af2c..792a4ee 100644 --- a/header.go +++ b/header.go @@ -1430,7 +1430,7 @@ func (h *ResponseHeader) setSpecialHeader(key, value []byte) bool { } // setNonSpecial directly put into map i.e. not a basic header. -func (h *ResponseHeader) setNonSpecial(key []byte, value []byte) { +func (h *ResponseHeader) setNonSpecial(key, value []byte) { h.h = setArgBytes(h.h, key, value, argsHasValue) } @@ -1489,7 +1489,7 @@ func (h *RequestHeader) setSpecialHeader(key, value []byte) bool { } // setNonSpecial directly put into map i.e. not a basic header. -func (h *RequestHeader) setNonSpecial(key []byte, value []byte) { +func (h *RequestHeader) setNonSpecial(key, value []byte) { h.h = setArgBytes(h.h, key, value, argsHasValue) } diff --git a/http.go b/http.go index e078809..f54a183 100644 --- a/http.go +++ b/http.go @@ -1201,7 +1201,7 @@ func (req *Request) ReadLimitBody(r *bufio.Reader, maxBodySize int) error { return req.readLimitBody(r, maxBodySize, false, true) } -func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error { +func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly, preParseMultipartForm bool) error { // Do not reset the request here - the caller must reset it before // calling this method. @@ -1219,7 +1219,7 @@ func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool return req.ContinueReadBody(r, maxBodySize, preParseMultipartForm) } -func (req *Request) readBodyStream(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error { +func (req *Request) readBodyStream(r *bufio.Reader, maxBodySize int, getOnly, preParseMultipartForm bool) error { // Do not reset the request here - the caller must reset it before // calling this method. @@ -1310,7 +1310,7 @@ func (req *Request) ContinueReadBody(r *bufio.Reader, maxBodySize int, preParseM // // If maxBodySize > 0 and the body size exceeds maxBodySize, // then ErrBodyTooLarge is returned. -func (req *Request) ReadBody(r *bufio.Reader, contentLength int, maxBodySize int) (err error) { +func (req *Request) ReadBody(r *bufio.Reader, contentLength, maxBodySize int) (err error) { bodyBuf := req.bodyBuffer() bodyBuf.Reset() @@ -2242,7 +2242,7 @@ func writeChunk(w *bufio.Writer, b []byte) error { // the given limit. var ErrBodyTooLarge = errors.New("body size exceeds the given limit") -func readBody(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ([]byte, error) { +func readBody(r *bufio.Reader, contentLength, maxBodySize int, dst []byte) ([]byte, error) { if maxBodySize > 0 && contentLength > maxBodySize { return dst, ErrBodyTooLarge } @@ -2251,7 +2251,7 @@ func readBody(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ( var errChunkedStream = errors.New("chunked stream") -func readBodyWithStreaming(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) (b []byte, err error) { +func readBodyWithStreaming(r *bufio.Reader, contentLength, maxBodySize int, dst []byte) (b []byte, err error) { if contentLength == -1 { // handled in requestStream.Read() return b, errChunkedStream diff --git a/http_test.go b/http_test.go index 5e2ce54..3e69b2d 100644 --- a/http_test.go +++ b/http_test.go @@ -2658,8 +2658,8 @@ func TestRequestRawBodyCopyTo(t *testing.T) { } type testReader struct { - read chan (int) - cb chan (struct{}) + read chan int + cb chan struct{} onClose func() error } diff --git a/prefork/prefork.go b/prefork/prefork.go index 225912d..d40bded 100644 --- a/prefork/prefork.go +++ b/prefork/prefork.go @@ -210,7 +210,8 @@ func (p *Prefork) prefork(addr string) (err error) { p.logger().Printf("one of the child prefork processes exited with "+ "error: %v", sig.err) - if exitedProcs++; exitedProcs > p.RecoverThreshold { + exitedProcs++ + if exitedProcs > p.RecoverThreshold { p.logger().Printf("child prefork processes exit too many times, "+ "which exceeds the value of RecoverThreshold(%d), "+ "exiting the master process.\n", exitedProcs) diff --git a/server.go b/server.go index 426351b..03b49f7 100644 --- a/server.go +++ b/server.go @@ -682,7 +682,7 @@ func (ctx *RequestCtx) Hijacked() bool { // All the values are removed from ctx after returning from the top // RequestHandler. Additionally, Close method is called on each value // implementing io.Closer before removing the value from ctx. -func (ctx *RequestCtx) SetUserValue(key any, value any) { +func (ctx *RequestCtx) SetUserValue(key, value any) { ctx.userValues.Set(key, value) } diff --git a/status.go b/status.go index c88ba11..f92727c 100644 --- a/status.go +++ b/status.go @@ -163,7 +163,7 @@ func StatusMessage(statusCode int) string { return unknownStatusCode } -func formatStatusLine(dst []byte, protocol []byte, statusCode int, statusText []byte) []byte { +func formatStatusLine(dst, protocol []byte, statusCode int, statusText []byte) []byte { dst = append(dst, protocol...) dst = append(dst, ' ') dst = strconv.AppendInt(dst, int64(statusCode), 10) diff --git a/userdata.go b/userdata.go index a9afbf5..38cca86 100644 --- a/userdata.go +++ b/userdata.go @@ -11,7 +11,7 @@ type userDataKV struct { type userData []userDataKV -func (d *userData) Set(key any, value any) { +func (d *userData) Set(key, value any) { if b, ok := key.([]byte); ok { key = string(b) } -- cgit v1.2.3