diff --git a/.golangci.yml b/.golangci.yml index 483c67ad5e..ad75ddf96d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,6 @@ linters: - cyclop - depguard - dupl - - dupword - errname - errorlint - exhaustive @@ -43,7 +42,6 @@ linters: - testpackage - thelper - tparallel - - unconvert - unparam - usestdlibvars - varnamelen diff --git a/brotli.go b/brotli.go index c829c39fa7..032bd953ec 100644 --- a/brotli.go +++ b/brotli.go @@ -132,7 +132,17 @@ func WriteBrotliLevel(w io.Writer, p []byte, level int) (int, error) { } } -var stacklessWriteBrotli = stackless.NewFunc(nonblockingWriteBrotli) +var ( + stacklessWriteBrotliOnce sync.Once + stacklessWriteBrotliFunc func(ctx interface{}) bool +) + +func stacklessWriteBrotli(ctx interface{}) { + stacklessWriteBrotliOnce.Do(func() { + stacklessWriteBrotliFunc = stackless.NewFunc(nonblockingWriteBrotli) + }) + stacklessWriteBrotliFunc(ctx) +} func nonblockingWriteBrotli(ctxv interface{}) { ctx := ctxv.(*compressCtx) diff --git a/bytesconv_test.go b/bytesconv_test.go index c9034ec0e5..444981061a 100644 --- a/bytesconv_test.go +++ b/bytesconv_test.go @@ -37,7 +37,7 @@ func TestAppendHTMLEscape(t *testing.T) { allcases[i] = byte(i) } res := string(AppendHTMLEscape(nil, string(allcases))) - expect := string(html.EscapeString(string(allcases))) + expect := html.EscapeString(string(allcases)) if res != expect { t.Fatalf("unexpected string %q. Expecting %q.", res, expect) } diff --git a/client.go b/client.go index 02456d313f..498de057c7 100644 --- a/client.go +++ b/client.go @@ -1474,6 +1474,7 @@ func (c *HostClient) acquireConn(reqTimeout time.Duration, connectionClose bool) return nil, ErrNoFreeConns } + //nolint:dupword // reqTimeout c.MaxConnWaitTimeout wait duration // d1 d2 min(d1, d2) // 0(not set) d2 d2 @@ -2542,8 +2543,8 @@ func (c *PipelineClient) newConnClient() *pipelineConnClient { } // ErrPipelineOverflow may be returned from PipelineClient.Do* -// if the requests' queue is overflown. -var ErrPipelineOverflow = errors.New("pipelined requests' queue has been overflown. Increase MaxConns and/or MaxPendingRequests") +// if the requests' queue is overflowed. +var ErrPipelineOverflow = errors.New("pipelined requests' queue has been overflowed. Increase MaxConns and/or MaxPendingRequests") // DefaultMaxPendingRequests is the default value // for PipelineClient.MaxPendingRequests. diff --git a/compress.go b/compress.go index 8494d569be..1f44f1e6fc 100644 --- a/compress.go +++ b/compress.go @@ -177,7 +177,17 @@ func WriteGzipLevel(w io.Writer, p []byte, level int) (int, error) { } } -var stacklessWriteGzip = stackless.NewFunc(nonblockingWriteGzip) +var ( + stacklessWriteGzipOnce sync.Once + stacklessWriteGzipFunc func(ctx interface{}) bool +) + +func stacklessWriteGzip(ctx interface{}) { + stacklessWriteGzipOnce.Do(func() { + stacklessWriteGzipFunc = stackless.NewFunc(nonblockingWriteGzip) + }) + stacklessWriteGzipFunc(ctx) +} func nonblockingWriteGzip(ctxv interface{}) { ctx := ctxv.(*compressCtx) @@ -270,7 +280,17 @@ func WriteDeflateLevel(w io.Writer, p []byte, level int) (int, error) { } } -var stacklessWriteDeflate = stackless.NewFunc(nonblockingWriteDeflate) +var ( + stacklessWriteDeflateOnce sync.Once + stacklessWriteDeflateFunc func(ctx interface{}) bool +) + +func stacklessWriteDeflate(ctx interface{}) { + stacklessWriteDeflateOnce.Do(func() { + stacklessWriteDeflateFunc = stackless.NewFunc(nonblockingWriteDeflate) + }) + stacklessWriteDeflateFunc(ctx) +} func nonblockingWriteDeflate(ctxv interface{}) { ctx := ctxv.(*compressCtx) diff --git a/fs.go b/fs.go index 9ada758843..c231d8031c 100644 --- a/fs.go +++ b/fs.go @@ -870,7 +870,7 @@ func (cm *inMemoryCacheManager) GetFileFromCache(cacheKind CacheKind, path strin fileCache := cm.getFsCache(cacheKind) cm.cacheLock.Lock() - ff, ok := fileCache[string(path)] + ff, ok := fileCache[path] if ok { ff.readersCount++ } @@ -1594,7 +1594,7 @@ func (h *fsHandler) newFSFile(f fs.File, fileInfo fs.FileInfo, compressed bool, } func readFileHeader(f io.Reader, compressed bool, fileEncoding string) ([]byte, error) { - r := io.Reader(f) + r := f var ( br *brotli.Reader zr *gzip.Reader diff --git a/http_test.go b/http_test.go index 0091566c7a..7b526cbd85 100644 --- a/http_test.go +++ b/http_test.go @@ -3022,7 +3022,7 @@ func TestResponseBodyStream(t *testing.T) { } }) - t.Run("limit response body size size", func(t *testing.T) { + t.Run("limit response body size", func(t *testing.T) { t.Parallel() client := Client{StreamResponseBody: true, MaxResponseBodySize: 20} diff --git a/stackless/writer.go b/stackless/writer.go index b0d3e8dd96..347e464a29 100644 --- a/stackless/writer.go +++ b/stackless/writer.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "sync" "github.com/valyala/bytebufferpool" ) @@ -98,7 +99,17 @@ func (w *writer) do(op op) error { var errHighLoad = errors.New("cannot compress data due to high load") -var stacklessWriterFunc = NewFunc(writerFunc) +var ( + stacklessWriterFuncOnce sync.Once + stacklessWriterFuncFunc func(ctx interface{}) bool +) + +func stacklessWriterFunc(ctx interface{}) bool { + stacklessWriterFuncOnce.Do(func() { + stacklessWriterFuncFunc = NewFunc(writerFunc) + }) + return stacklessWriterFuncFunc(ctx) +} func writerFunc(ctx interface{}) { w := ctx.(*writer)