From b36f3834eb5cefbd25c85777df9b362ddc6c2820 Mon Sep 17 00:00:00 2001 From: fatedier Date: Wed, 20 Mar 2024 15:48:31 +0800 Subject: [PATCH] use math/rand/v2 (#4020) --- .github/workflows/golangci-lint.yml | 2 +- .golangci.yml | 27 +++++++++------------------ pkg/nathole/nathole.go | 6 +++--- pkg/util/util/util.go | 4 ++-- pkg/util/wait/backoff.go | 2 +- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 18f69d5..b3e2cb4 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -23,7 +23,7 @@ jobs: uses: golangci/golangci-lint-action@v4 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.56 + version: v1.57 # Optional: golangci-lint command line arguments. # args: --issues-exit-code=0 diff --git a/.golangci.yml b/.golangci.yml index cd92e43..e2f8a24 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ service: - golangci-lint-version: 1.56.x # use the fixed version to not introduce new linters unexpectedly + golangci-lint-version: 1.57.x # use the fixed version to not introduce new linters unexpectedly run: concurrency: 4 @@ -8,23 +8,6 @@ run: build-tags: - integ - integfuzz - # which dirs to skip: they won't be analyzed; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but next dirs are always skipped independently - # from this option's value: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - skip-dirs: - - genfiles$ - - vendor$ - - bin$ - - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - skip-files: - - ".*\\.pb\\.go" - - ".*\\.gen\\.go" linters: disable-all: true @@ -136,6 +119,14 @@ issues: - unparam text: "is always false" + exclude-dirs: + - genfiles$ + - vendor$ + - bin$ + exclude-files: + - ".*\\.pb\\.go" + - ".*\\.gen\\.go" + # Independently from option `exclude` we use default exclude patterns, # it can be disabled by this option. To list all # excluded by default patterns execute `golangci-lint run --help`. diff --git a/pkg/nathole/nathole.go b/pkg/nathole/nathole.go index 18cd12b..bdd0ee8 100644 --- a/pkg/nathole/nathole.go +++ b/pkg/nathole/nathole.go @@ -17,7 +17,7 @@ package nathole import ( "context" "fmt" - "math/rand" + "math/rand/v2" "net" "slices" "strconv" @@ -341,7 +341,7 @@ func sendSidMessage( TransactionID: transactionID, Sid: sid, Response: false, - Nonce: strings.Repeat("0", rand.Intn(20)), + Nonce: strings.Repeat("0", rand.IntN(20)), } buf, err := EncodeMessage(m, key) if err != nil { @@ -398,7 +398,7 @@ func sendSidMessageToRandomPorts( used := sets.New[int]() getUnusedPort := func() int { for i := 0; i < 10; i++ { - port := rand.Intn(65535-1024) + 1024 + port := rand.IntN(65535-1024) + 1024 if !used.Has(port) { used.Insert(port) return port diff --git a/pkg/util/util/util.go b/pkg/util/util/util.go index c7fd997..7758054 100644 --- a/pkg/util/util/util.go +++ b/pkg/util/util/util.go @@ -20,7 +20,7 @@ import ( "crypto/subtle" "encoding/hex" "fmt" - mathrand "math/rand" + mathrand "math/rand/v2" "net" "strconv" "strings" @@ -124,7 +124,7 @@ func RandomSleep(duration time.Duration, minRatio, maxRatio float64) time.Durati if max <= min { n = min } else { - n = mathrand.Int63n(max-min) + min + n = mathrand.Int64N(max-min) + min } d := duration * time.Duration(n) / time.Duration(1000) time.Sleep(d) diff --git a/pkg/util/wait/backoff.go b/pkg/util/wait/backoff.go index 16d9dd6..4d01ace 100644 --- a/pkg/util/wait/backoff.go +++ b/pkg/util/wait/backoff.go @@ -15,7 +15,7 @@ package wait import ( - "math/rand" + "math/rand/v2" "time" "github.com/fatedier/frp/pkg/util/util"