From 776c0b628b06d455985794b2a4029c2131b9d991 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Fri, 25 Apr 2025 12:22:24 +0700 Subject: [PATCH 1/2] sav --- .github/workflows/go-checks.yml | 6 +- .golangci.yml | 244 ++++++++++++++++-------------- Makefile | 2 +- cmd/diagnostics/main.go | 3 +- internal/erigon_node/remote_db.go | 4 +- 5 files changed, 138 insertions(+), 121 deletions(-) diff --git a/.github/workflows/go-checks.yml b/.github/workflows/go-checks.yml index 0be45a6..7dae202 100644 --- a/.github/workflows/go-checks.yml +++ b/.github/workflows/go-checks.yml @@ -13,10 +13,10 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.22' + go-version: '1.23' - run: go mod tidy - - uses: golangci/golangci-lint-action@v6 + - uses: golangci/golangci-lint-action@v7 with: - version: 'v1.61' + version: 'v2.1.5' - run: go build -v ./... - run: go test -v ./... diff --git a/.golangci.yml b/.golangci.yml index e7b2fda..d2df0cf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,122 +1,138 @@ -run: - timeout: 10m - +version: "2" linters: - presets: - - bugs - - error + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - durationcheck + - fatcontext + - gochecksumtype + - gocritic + - gosec + - gosmopolitan + - loggercheck + - nilnesserr + - prealloc + - protogetter + - reassign + - recvcheck + - rowserrcheck + - spancheck + - sqlclosecheck + - testifylint + - unconvert + - zerologlint + - makezero + - noctx + - nilerr + - errorlint - unused - - performance disable: - - exhaustive - - musttag - - contextcheck - - wrapcheck - - goerr113 - - unparam - - makezero #TODO: enable me - - noctx #TODO: enable me - - nilerr #TODO: enable me - - errorlint #TODO: enable me - errchkjson #TODO: enable me - - unused #TODO: enable me - perfsprint #TODO: enable me + - contextcheck + - err113 + - exhaustive - gocheckcompilerdirectives + - musttag + - unparam + - wrapcheck + settings: + goconst: + min-len: 2 + min-occurrences: 2 + gocritic: + disabled-checks: + - rangeValCopy + - exitAfterDefer + - elseif + - dupBranchBody + - assignOp + - singleCaseSwitch + - captLocal + - commentFormatting + - ifElseChain + - sprintfQuotedString + - commentedOutCode + - preferFprint + - importShadow + - emptyStringTest + - paramTypeCombine + - unnamedResult + enabled-tags: + - performance + - diagnostic + - style + settings: + rangeExprCopy: + sizeThreshold: 512 + skipTestFuncs: true + underef: + skipRecvDeref: true + govet: + disable: + - deepequalerrors + - fieldalignment + - shadow + - unsafeptr + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - golint + text: should be + - linters: + - errcheck + text: not checked + - linters: + - staticcheck + text: SA(1019|1029|5011) + - linters: + - gocritic + - gosec + - unused + path: test\.go + - linters: + - gocritic + - gosec + - unused + path: hack\.go + - linters: + - gocritic + - gosec + - unused + path: cmd/devp2p + - linters: + - gocritic + - gosec + path: metrics/sample\.go + - linters: + - gocritic + - gosec + path: p2p/simulations + - linters: + - gocritic + - gosec + path: p2p/dnsdisc + paths: + - third_party$ + - builtin$ + - examples$ +formatters: enable: - - unconvert - # - predeclared #TODO: enable me - # - thelper #TODO: enable me - # - wastedassign - gofmt - - gocritic -# - revive -# - forcetypeassert -# - stylecheck - -linters-settings: - gocritic: # see https://golangci-lint.run/usage/linters/#gocritic and https://go-critic.github.io/overview#checks-overview - enabled-tags: - - performance - - diagnostic - - style - disabled-checks: - - rangeValCopy - - exitAfterDefer - - elseif - - dupBranchBody - - assignOp - - singleCaseSwitch - - captLocal - - commentFormatting - - ifElseChain - - sprintfQuotedString - - commentedOutCode - - preferFprint - - # style tag - - importShadow - - emptyStringTest - - paramTypeCombine - - unnamedResult - - settings: - rangeExprCopy: - # size in bytes that makes the warning trigger (default 512) - sizeThreshold: 512 - # whether to check test functions (default true) - skipTestFuncs: true - underef: - # whether to skip (*x).method() calls where x is a pointer receiver (default true) - skipRecvDeref: true - - govet: - disable: - - deepequalerrors - - fieldalignment - - shadow - - unsafeptr - goconst: - min-len: 2 - min-occurrences: 2 - gofmt: - simplify: false - -issues: - exclude-rules: - - linters: - - golint - text: "should be" - - linters: - - errcheck - text: "not checked" - - linters: - - staticcheck - text: "SA(1019|1029|5011)" - # Exclude some linters from running on tests files. - - path: test\.go - linters: - - gosec - - unused - - gocritic - - path: hack\.go - linters: - - gosec - - unused - - gocritic - - path: cmd/devp2p - linters: - - gosec - - unused - - gocritic - - path: metrics/sample\.go - linters: - - gosec - - gocritic - - path: p2p/simulations - linters: - - gosec - - gocritic - - path: p2p/dnsdisc - linters: - - gosec - - gocritic + settings: + gofmt: + simplify: false + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index a5e91e4..6d16e32 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,6 @@ lintci: ## lintci-deps: (re)installs golangci-lint to build/bin/golangci-lint lintci-deps: rm -f ./build/bin/golangci-lint - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.57.2 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v2.1.5 .PHONY: build test run clean \ No newline at end of file diff --git a/cmd/diagnostics/main.go b/cmd/diagnostics/main.go index 202fa87..9091629 100644 --- a/cmd/diagnostics/main.go +++ b/cmd/diagnostics/main.go @@ -3,6 +3,7 @@ package main import ( "bufio" "context" + "errors" "fmt" "log" "net/http" @@ -72,7 +73,7 @@ func main() { switch s := <-signalCh; s { case syscall.SIGTERM: log.Println("Terminating gracefully.") - if err := srv.Shutdown(context.Background()); err != http.ErrServerClosed { + if err := srv.Shutdown(context.Background()); !errors.Is(err, http.ErrServerClosed) { log.Println("Failed to shutdown server:", err) } case syscall.SIGINT: diff --git a/internal/erigon_node/remote_db.go b/internal/erigon_node/remote_db.go index b555366..9c21bbf 100644 --- a/internal/erigon_node/remote_db.go +++ b/internal/erigon_node/remote_db.go @@ -145,13 +145,13 @@ func (rc *RemoteCursor) findFullDbPath(ctx context.Context, db string) (string, request, err := rc.nodeClient.fetch(ctx, "dbs", nil) if err != nil { - return "", fmt.Errorf("unable to fetch database list: %s", err) + return "", fmt.Errorf("unable to fetch database list: %w", err) } _, result, err := request.nextResult(ctx) if err != nil { - return "", fmt.Errorf("unable to fetch database list: %s", err) + return "", fmt.Errorf("unable to fetch database list: %w", err) } var lines []string From a7aab750fb885d77057f6d8ae0699e5ddf64e535 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Fri, 25 Apr 2025 12:22:49 +0700 Subject: [PATCH 2/2] sav --- internal/sessions/helpers.go | 18 ------------------ internal/sessions/middleware.go | 4 ---- 2 files changed, 22 deletions(-) delete mode 100644 internal/sessions/helpers.go diff --git a/internal/sessions/helpers.go b/internal/sessions/helpers.go deleted file mode 100644 index 7f2e35b..0000000 --- a/internal/sessions/helpers.go +++ /dev/null @@ -1,18 +0,0 @@ -package sessions - -import ( - "crypto/rand" - "math/big" -) - -func generatePIN() (uint64, error) { - //if insecure { TODO fix this - // return uint64(weakrand.Int63n(100_000_000)), nil - //} - _max := big.NewInt(100_000_000) // For an 8-digit PIN - randNum, err := rand.Int(rand.Reader, _max) - if err != nil { - return 0, err - } - return randNum.Uint64(), nil -} diff --git a/internal/sessions/middleware.go b/internal/sessions/middleware.go index b5e1e11..7bb2022 100644 --- a/internal/sessions/middleware.go +++ b/internal/sessions/middleware.go @@ -4,10 +4,6 @@ import ( "net/http" ) -const sessionIdCookieName = "sessionId" - -const sessionIdCookieDuration = 30 * 24 * 3600 // 30 days - type Middleware struct { CacheService }