From f3bce3aa6e9450a6f69ae3f98b6db0958d67233c Mon Sep 17 00:00:00 2001 From: Aoang Date: Sun, 20 Mar 2022 21:34:31 +0800 Subject: [PATCH] Add Go 1.18 support (#1253) * Add Go 1.18 support * fix Gosec Security Scanner https://github.com/valyala/fasthttp/runs/5595618634?check_suite_focus=true * fix https://github.com/securego/gosec/issues/469#issuecomment-1070608395 Gosec Github Action Doesn't Work at Go 1.18 * fix https://github.com/golangci/golangci-lint/pull/2438 golangci/golangci-lint Doesn't Work at Go 1.18 * fix golint unused * fix golint: SA1019: netErr.Temporary is deprecated * fix https://github.com/valyala/fasthttp/issues/1256 --- .github/workflows/lint.yml | 11 +++++++---- .github/workflows/security.yml | 11 ++++++++--- .github/workflows/test.yml | 2 +- client.go | 4 ++-- nocopy.go | 4 ++-- server.go | 8 ++++---- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5130b05f24..6c2c7b0546 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,9 +11,12 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: 1.17.x + go-version: 1.18.x - run: go version - run: diff -u <(echo -n) <(gofmt -d .) - - uses: golangci/golangci-lint-action@v2 - with: - version: v1.28.3 + - name: Run golangci-lint + run: | # https://github.com/golangci/golangci-lint/pull/2438 + export PATH=$PATH:$(go env GOPATH)/bin + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2 + golangci-lint run + diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 13b8fa76af..07c61ed57e 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -8,9 +8,11 @@ jobs: test: strategy: matrix: - go-version: [1.17.x] + go-version: [1.18.x] platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} + env: + GO111MODULE: on steps: - name: Install Go uses: actions/setup-go@v1 @@ -18,5 +20,8 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout code uses: actions/checkout@v2 - - name: Security - run: go get github.com/securego/gosec/cmd/gosec; `go env GOPATH`/bin/gosec -exclude=G104,G304 ./... + - name: Run Gosec Security Scanner + run: | # https://github.com/securego/gosec/issues/469#issuecomment-1070608395 + export PATH=$PATH:$(go env GOPATH)/bin + go install github.com/securego/gosec/v2/cmd/gosec@latest + gosec -exclude=G104,G304,G402 ./... diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 068a6f5cd0..429c155418 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: test: strategy: matrix: - go-version: [1.15.x, 1.16.x, 1.17.x] + go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: diff --git a/client.go b/client.go index ee05507a86..aea74116fb 100644 --- a/client.go +++ b/client.go @@ -2631,8 +2631,8 @@ func (c *pipelineConnClient) init() { for { if err := c.worker(); err != nil { c.logger().Printf("error in PipelineClient(%q): %s", c.Addr, err) - if netErr, ok := err.(net.Error); ok && netErr.Temporary() { - // Throttle client reconnections on temporary errors + if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + // Throttle client reconnections on timeout errors time.Sleep(time.Second) } } else { diff --git a/nocopy.go b/nocopy.go index 9664cb06b6..5e41bdf40d 100644 --- a/nocopy.go +++ b/nocopy.go @@ -7,5 +7,5 @@ package fasthttp // and also: https://stackoverflow.com/questions/52494458/nocopy-minimal-example type noCopy struct{} //nolint:unused -func (*noCopy) Lock() {} -func (*noCopy) Unlock() {} +func (*noCopy) Lock() {} //nolint:unused +func (*noCopy) Unlock() {} //nolint:unused diff --git a/server.go b/server.go index 3b585422d9..3ff678ce02 100644 --- a/server.go +++ b/server.go @@ -482,7 +482,7 @@ func TimeoutWithCodeHandler(h RequestHandler, timeout time.Duration, msg string, } } -//RequestConfig configure the per request deadline and body limits +// RequestConfig configure the per request deadline and body limits type RequestConfig struct { // ReadTimeout is the maximum duration for reading the entire // request body. @@ -1915,8 +1915,8 @@ func acceptConn(s *Server, ln net.Listener, lastPerIPErrorTime *time.Time) (net. if c != nil { panic("BUG: net.Listener returned non-nil conn and non-nil error") } - if netErr, ok := err.(net.Error); ok && netErr.Temporary() { - s.logger().Printf("Temporary error when accepting new connections: %s", netErr) + if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + s.logger().Printf("Timeout error when accepting new connections: %s", netErr) time.Sleep(time.Second) continue } @@ -2230,7 +2230,7 @@ func (s *Server) serveConn(c net.Conn) (err error) { writeTimeout = reqConf.WriteTimeout } } - //read body + // read body if s.StreamRequestBody { err = ctx.Request.readBodyStream(br, maxRequestBodySize, s.GetOnly, !s.DisablePreParseMultipartForm) } else {