Skip to content

Commit

Permalink
Enable few gocritic checks; fix up issues (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Mar 2, 2024
1 parent 9c69fea commit 3166afd
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 21 deletions.
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ linters-settings:
- style
disabled-checks:
- deferInLoop
- httpNoBody
- importShadow
- initClause
- paramTypeCombine
- sloppyReassign
- typeUnparen
- unnamedResult
- whyNoLint

Expand Down
4 changes: 2 additions & 2 deletions client_timing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion prefork/prefork.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 3166afd

Please sign in to comment.