From b8a775835512316a488274512dcad2592813d85f Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 26 Oct 2024 11:21:54 +0200 Subject: [PATCH 1/7] bump go version and se gotip --- .github/workflows/test.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 242bb8dbe..4e9c91b0f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,9 +13,9 @@ jobs: fail-fast: false matrix: go_version: - - '1.18' - - '1.19' - - '1.20' + - '1.21' + - '1.22' + - '1.23' - tip name: Test with ${{ matrix.go_version }} steps: @@ -29,16 +29,19 @@ jobs: - name: Install Go ${{ matrix.go_version }} if: ${{ matrix.go_version == 'tip' }} run: | - curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz - ls -lah gotip.tar.gz - mkdir -p ~/sdk/gotip - tar -C ~/sdk/gotip -xzf gotip.tar.gz - echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV + go install golang.org/dl/gotip@latest + gotip download - name: Vet and test + if: ${{ matrix.go_version != 'tip' }} run: | go version go vet ./... go test ./... + if: ${{ matrix.go_version == 'tip' }} + run: | + gotip version + gotip vet ./... + gotip test ./... golangci: name: Linting runs-on: ubuntu-latest @@ -46,7 +49,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@master with: - go-version: '1.20' + go-version: '1.23' check-latest: true - name: golangci-lint uses: golangci/golangci-lint-action@v2 From d2727e5a312d77b70bb5f8429a1902945c78cabb Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 26 Oct 2024 11:22:39 +0200 Subject: [PATCH 2/7] bump go version and se gotip --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e9c91b0f..d8699d96b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: go version go vet ./... go test ./... - if: ${{ matrix.go_version == 'tip' }} + else: run: | gotip version gotip vet ./... From 7ea1a25c0e5cafd97569d1528d8582c3617580eb Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 26 Oct 2024 11:23:14 +0200 Subject: [PATCH 3/7] bump go version and se gotip --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8699d96b..325c56934 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,13 +31,14 @@ jobs: run: | go install golang.org/dl/gotip@latest gotip download - - name: Vet and test + - name: Vet and test no tip if: ${{ matrix.go_version != 'tip' }} run: | go version go vet ./... go test ./... - else: + - name: Vet and test gotip + if: ${{ matrix.go_version == 'tip' }} run: | gotip version gotip vet ./... From 3cf1b3eda646518c4fee3aebe4f3e9d544050d1d Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 26 Oct 2024 11:26:46 +0200 Subject: [PATCH 4/7] bump go version and se gotip --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 325c56934..f33e16543 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: if: ${{ matrix.go_version == 'tip' }} run: | go install golang.org/dl/gotip@latest - gotip download + ${GOPATH}/bin/gotip download - name: Vet and test no tip if: ${{ matrix.go_version != 'tip' }} run: | @@ -40,9 +40,9 @@ jobs: - name: Vet and test gotip if: ${{ matrix.go_version == 'tip' }} run: | - gotip version - gotip vet ./... - gotip test ./... + ${GOPATH}/bin/gotip version + ${GOPATH}/bin/gotip vet ./... + ${GOPATH}/bin/gotip test ./... golangci: name: Linting runs-on: ubuntu-latest From b6a7f59230d2e20433e52db15def12dcc6a004af Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 26 Oct 2024 11:35:53 +0200 Subject: [PATCH 5/7] linting --- server/handlers_test.go | 4 ++-- server/server.go | 5 ++++- server/token.go | 6 +----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/server/handlers_test.go b/server/handlers_test.go index 2c76ffdfb..f8f14ca1e 100644 --- a/server/handlers_test.go +++ b/server/handlers_test.go @@ -26,7 +26,7 @@ func (s *suiteRedirectWithForceHTTPS) SetUpTest(c *C) { c.Assert(err, IsNil) handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Hello, client") + _, _ = fmt.Fprintln(w, "Hello, client") }) s.handler = srvr.RedirectHandler(handler) @@ -83,7 +83,7 @@ func (s *suiteRedirectWithoutForceHTTPS) SetUpTest(c *C) { c.Assert(err, IsNil) handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Hello, client") + _, _ = fmt.Fprintln(w, "Hello, client") }) s.handler = srvr.RedirectHandler(handler) diff --git a/server/server.go b/server/server.go index 23eb5c350..b7a4e926d 100644 --- a/server/server.go +++ b/server/server.go @@ -402,12 +402,15 @@ func New(options ...OptionFn) (*Server, error) { return s, nil } +var theRand *rand.Rand + func init() { var seedBytes [8]byte if _, err := cryptoRand.Read(seedBytes[:]); err != nil { panic("cannot obtain cryptographically secure seed") } - rand.Seed(int64(binary.LittleEndian.Uint64(seedBytes[:]))) + + theRand = rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(seedBytes[:])))) } // Run starts Server diff --git a/server/token.go b/server/token.go index f3aa012ed..d73403ebc 100644 --- a/server/token.go +++ b/server/token.go @@ -24,10 +24,6 @@ THE SOFTWARE. package server -import ( - "math/rand" -) - const ( // SYMBOLS characters used for short-urls SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -37,7 +33,7 @@ const ( func token(length int) string { result := "" for i := 0; i < length; i++ { - x := rand.Intn(len(SYMBOLS) - 1) + x := theRand.Intn(len(SYMBOLS) - 1) result = string(SYMBOLS[x]) + result } From 227854168bd0d3e0d4636794296e0e8d43badd77 Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 26 Oct 2024 11:40:09 +0200 Subject: [PATCH 6/7] gobin --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f33e16543..9a4093c94 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: if: ${{ matrix.go_version == 'tip' }} run: | go install golang.org/dl/gotip@latest - ${GOPATH}/bin/gotip download + `go env GOBIN`/gotip download - name: Vet and test no tip if: ${{ matrix.go_version != 'tip' }} run: | @@ -40,9 +40,9 @@ jobs: - name: Vet and test gotip if: ${{ matrix.go_version == 'tip' }} run: | - ${GOPATH}/bin/gotip version - ${GOPATH}/bin/gotip vet ./... - ${GOPATH}/bin/gotip test ./... + `go env GOBIN`/gotip version + `go env GOBIN`/gotip vet ./... + `go env GOBIN`/gotip test ./... golangci: name: Linting runs-on: ubuntu-latest From f044c188ef06404cddedc5544846d08ebfa7b905 Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sat, 26 Oct 2024 11:41:53 +0200 Subject: [PATCH 7/7] GOPATH --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a4093c94..a6734362d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: if: ${{ matrix.go_version == 'tip' }} run: | go install golang.org/dl/gotip@latest - `go env GOBIN`/gotip download + `go env GOPATH`/bin/gotip download - name: Vet and test no tip if: ${{ matrix.go_version != 'tip' }} run: | @@ -40,9 +40,9 @@ jobs: - name: Vet and test gotip if: ${{ matrix.go_version == 'tip' }} run: | - `go env GOBIN`/gotip version - `go env GOBIN`/gotip vet ./... - `go env GOBIN`/gotip test ./... + `go env GOPATH`/bin/gotip version + `go env GOPATH`/bin/gotip vet ./... + `go env GOPATH`/bin/gotip test ./... golangci: name: Linting runs-on: ubuntu-latest