valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.91k stars 1.76k forks source link

Enable several gocritic checks; resolve identified issues #1728

Closed alexandear closed 8 months ago

alexandear commented 8 months ago

The PR enables temporarily disabled httpNoBody, initClause, paramTypeCombine, typeUnparen checks from gocritic linter and fixes up lint issues.

❯ golangci-lint run
fs.go:1353:1: paramTypeCombine: func(filePath string, fileEncoding string) (*fsFile, error) could be replaced with func(filePath, fileEncoding string) (*fsFile, error) (gocritic)
func (h *fsHandler) compressAndOpenFSFile(filePath string, fileEncoding string) (*fsFile, error) {
^
fs.go:1535:1: paramTypeCombine: func(filePath string, fileEncoding string) (*fsFile, error) could be replaced with func(filePath, fileEncoding string) (*fsFile, error) (gocritic)
func (h *fsHandler) newCompressedFSFile(filePath string, fileEncoding string) (*fsFile, error) {
^
header.go:1433:1: paramTypeCombine: func(key []byte, value []byte) could be replaced with func(key, value []byte) (gocritic)
func (h *ResponseHeader) setNonSpecial(key []byte, value []byte) {
^
header.go:1492:1: paramTypeCombine: func(key []byte, value []byte) could be replaced with func(key, value []byte) (gocritic)
func (h *RequestHeader) setNonSpecial(key []byte, value []byte) {
^
http.go:1204:1: paramTypeCombine: func(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error could be replaced with func(r *bufio.Reader, maxBodySize int, getOnly, preParseMultipartForm bool) error (gocritic)
func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error {
^
http.go:1222:1: paramTypeCombine: func(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error could be replaced with func(r *bufio.Reader, maxBodySize int, getOnly, preParseMultipartForm bool) error (gocritic)
func (req *Request) readBodyStream(r *bufio.Reader, maxBodySize int, getOnly bool, preParseMultipartForm bool) error {
^
http.go:1313:1: paramTypeCombine: func(r *bufio.Reader, contentLength int, maxBodySize int) (err error) could be replaced with func(r *bufio.Reader, contentLength, maxBodySize int) (err error) (gocritic)
func (req *Request) ReadBody(r *bufio.Reader, contentLength int, maxBodySize int) (err error) {
^
http.go:2245:1: paramTypeCombine: func(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ([]byte, error) could be replaced with func(r *bufio.Reader, contentLength, maxBodySize int, dst []byte) ([]byte, error) (gocritic)
func readBody(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) ([]byte, error) {
^
http.go:2254:1: paramTypeCombine: func(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) (b []byte, err error) could be replaced with func(r *bufio.Reader, contentLength, maxBodySize int, dst []byte) (b []byte, err error) (gocritic)
func readBodyWithStreaming(r *bufio.Reader, contentLength int, maxBodySize int, dst []byte) (b []byte, err error) {
^
server.go:685:1: paramTypeCombine: func(key any, value any) could be replaced with func(key, value any) (gocritic)
func (ctx *RequestCtx) SetUserValue(key any, value any) {
^
status.go:166:1: paramTypeCombine: func(dst []byte, protocol []byte, statusCode int, statusText []byte) []byte could be replaced with func(dst, protocol []byte, statusCode int, statusText []byte) []byte (gocritic)
func formatStatusLine(dst []byte, protocol []byte, statusCode int, statusText []byte) []byte {
^
userdata.go:14:1: paramTypeCombine: func(key any, value any) could be replaced with func(key, value any) (gocritic)
func (d *userData) Set(key any, value any) {
^
client_timing_test.go:168:15: httpNoBody: http.NoBody should be preferred to the nil request body (gocritic)
                req, err := http.NewRequest(MethodGet, fmt.Sprintf("http://foobar%d.com/aaa/bbb", atomic.AddUint32(&nn, 1)), nil)
                            ^
client_timing_test.go:553:15: httpNoBody: http.NoBody should be preferred to the nil request body (gocritic)
                req, err := http.NewRequest(MethodGet, url, nil)
                            ^
http_test.go:2661:10: typeUnparen: could simplify chan (int) to chan int (gocritic)
        read    chan (int)
                ^
http_test.go:2662:10: typeUnparen: could simplify chan (struct{}) to chan struct{} (gocritic)
        cb      chan (struct{})
                ^
prefork/prefork.go:213:3: initClause: consider to move `exitedProcs++` before if (gocritic)
                if exitedProcs++; exitedProcs > p.RecoverThreshold {
                ^
erikdubbelboer commented 8 months ago

Great, thanks!