From 38a9bf86e05c51fbf6b44bb675efc36dafcb357f Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Fri, 5 Sep 2025 16:06:52 +0200 Subject: [PATCH 1/2] added auto-generated agents.md --- AGENTS.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..a6a854e --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,38 @@ +# Repository Guidelines + +## Project Structure & Module Organization +- Source layout: `cmd/cli` and `cmd/httpserver` are entrypoints; shared packages live in `common/`, `httpserver/`, `database/`, and `metrics/`. +- Tests: co-located `*_test.go` files (e.g., `httpserver/handler_test.go`, `database/database_test.go`). +- Artifacts: binaries output to `build/` via Makefile targets. Dockerfiles: `cli.dockerfile`, `httpserver.dockerfile`. +- Go version: 1.24 (see `go.mod`). Module path: `github.com/flashbots/go-template`. + +## Build, Test, and Development Commands +- `make build`: builds CLI and HTTP server into `build/`. +- `make build-cli` / `make build-httpserver`: build individual binaries. +- `make lint`: run formatters and linters (`gofmt`, `gofumpt`, `go vet`, `staticcheck`, `golangci-lint`). +- `make test` / `make test-race`: run tests (optionally with race detector). +- `make fmt`: apply formatting (`gofmt`, `gci`, `gofumpt`) and `go mod tidy`. +- `make cover` / `make cover-html`: coverage summary / HTML report. +- Docker: `make docker-cli`, `make docker-httpserver` build images using the respective Dockerfiles. + +## Coding Style & Naming Conventions +- Formatting: run `make fmt` before committing. Go files must pass `golangci-lint` (config in `.golangci.yaml`). +- Style: idiomatic Go; exported identifiers use CamelCase; packages lower-case short names; errors returned, not panicked. +- JSON tags: prefer snake_case (configured via `tagliatelle`). +- Logging: use `common.SetupLogger` (slog) and structured fields; respect `--log-json` and `--log-debug` flags. + +## Testing Guidelines +- Framework: standard `testing` with `testify/require` for assertions. +- Run: `make test` (or `go test ./...`). +- Database tests: gated by `RUN_DB_TESTS=1` and a Postgres instance. Example: + - `docker run -d --name postgres-test -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres` + - `RUN_DB_TESTS=1 make test` +- Coverage: aim to keep or increase coverage; use `make cover`. + +## Commit & Pull Request Guidelines +- Commits: concise, imperative mood; scope prefixes like `ci:`, `docs:`, `fix:`, `feat:` when helpful. Reference issues/PRs. +- PRs: include a clear description, linked issues, test plan (commands run), and any config notes. Ensure `make fmt lint test` pass locally. + +## Security & Configuration Tips +- Configuration: prefer flags/env via `common.GetEnv` and CLI options; avoid hardcoding secrets. +- HTTP server: `/debug` (pprof) is opt-in; do not expose publicly. Metrics on `/metrics` (Prometheus format). From c8ed36693daa1a93523103f4f5cb6cd21d9aa4cb Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Mon, 8 Sep 2025 10:59:58 +0200 Subject: [PATCH 2/2] updarte golangci-lint to v2 --- .github/workflows/checks.yml | 5 +---- .golangci.yaml | 19 +++++++++++++++++-- AGENTS.md | 14 ++++++++------ database/database.go | 6 +++--- httpserver/handler_test.go | 10 +++++----- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 4aea049..965cc19 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -67,10 +67,7 @@ jobs: run: go install honnef.co/go/tools/cmd/staticcheck@2025.1.1 - name: Install golangci-lint - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8 - - # - name: Install NilAway - # run: go install go.uber.org/nilaway/cmd/nilaway@v0.0.0-20240821220108-c91e71c080b7 + run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.2 - name: Lint run: make lint diff --git a/.golangci.yaml b/.golangci.yaml index 3a189a0..64579af 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,10 +1,10 @@ +version: "2" linters: enable-all: true disable: - cyclop - forbidigo - funlen - - gci - gochecknoglobals - gochecknoinits - gocritic @@ -39,7 +39,6 @@ linters: # # Disabled because deprecated: # - - tenv linters-settings: # @@ -87,3 +86,19 @@ linters-settings: - 'MockBeaconClient' - 'RelayAPI' - 'Webserver' + +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + settings: + gofumpt: + extra-rules: true + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/AGENTS.md b/AGENTS.md index a6a854e..4ede2bf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,6 +6,14 @@ - Artifacts: binaries output to `build/` via Makefile targets. Dockerfiles: `cli.dockerfile`, `httpserver.dockerfile`. - Go version: 1.24 (see `go.mod`). Module path: `github.com/flashbots/go-template`. +## Coding Style & Naming Conventions +- Use tabs instead of spaces for indentation. +- Always run `make fmt` and `make lint` (and `make test`) before committing. +- Formatting: run `make fmt` before committing. Go files must pass `golangci-lint` (config in `.golangci.yaml`). +- Style: idiomatic Go; exported identifiers use CamelCase; packages lower-case short names; errors returned, not panicked. +- JSON tags: prefer snake_case (configured via `tagliatelle`). +- Logging: use `common.SetupLogger` (slog) and structured fields; respect `--log-json` and `--log-debug` flags. + ## Build, Test, and Development Commands - `make build`: builds CLI and HTTP server into `build/`. - `make build-cli` / `make build-httpserver`: build individual binaries. @@ -15,12 +23,6 @@ - `make cover` / `make cover-html`: coverage summary / HTML report. - Docker: `make docker-cli`, `make docker-httpserver` build images using the respective Dockerfiles. -## Coding Style & Naming Conventions -- Formatting: run `make fmt` before committing. Go files must pass `golangci-lint` (config in `.golangci.yaml`). -- Style: idiomatic Go; exported identifiers use CamelCase; packages lower-case short names; errors returned, not panicked. -- JSON tags: prefer snake_case (configured via `tagliatelle`). -- Logging: use `common.SetupLogger` (slog) and structured fields; respect `--log-json` and `--log-debug` flags. - ## Testing Guidelines - Framework: standard `testing` with `testify/require` for assertions. - Run: `make test` (or `go test ./...`). diff --git a/database/database.go b/database/database.go index 3ab1601..5f08b92 100644 --- a/database/database.go +++ b/database/database.go @@ -21,9 +21,9 @@ func NewDatabaseService(dsn string) (*DatabaseService, error) { return nil, err } - db.DB.SetMaxOpenConns(50) - db.DB.SetMaxIdleConns(10) - db.DB.SetConnMaxIdleTime(0) + db.SetMaxOpenConns(50) + db.SetMaxIdleConns(10) + db.SetConnMaxIdleTime(0) if os.Getenv("DB_DONT_APPLY_SCHEMA") == "" { migrate.SetTable(vars.TableMigrations) diff --git a/httpserver/handler_test.go b/httpserver/handler_test.go index ed23461..ff16705 100644 --- a/httpserver/handler_test.go +++ b/httpserver/handler_test.go @@ -40,7 +40,7 @@ func Test_Handlers_Healthcheck_Drain_Undrain(t *testing.T) { w := httptest.NewRecorder() s.handleReadinessCheck(w, req) resp := w.Result() - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck _, err := io.ReadAll(resp.Body) require.NoError(t, err) require.Equal(t, http.StatusOK, resp.StatusCode, "Healthcheck must return `Ok` before draining") @@ -53,7 +53,7 @@ func Test_Handlers_Healthcheck_Drain_Undrain(t *testing.T) { s.handleDrain(w, req) duration := time.Since(start) resp := w.Result() - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck _, err := io.ReadAll(resp.Body) require.NoError(t, err) require.Equal(t, http.StatusOK, resp.StatusCode, "Must return `Ok` for calls to `/drain`") @@ -65,7 +65,7 @@ func Test_Handlers_Healthcheck_Drain_Undrain(t *testing.T) { w := httptest.NewRecorder() s.handleReadinessCheck(w, req) resp := w.Result() - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck _, err := io.ReadAll(resp.Body) require.NoError(t, err) require.Equal(t, http.StatusServiceUnavailable, resp.StatusCode, "Healthcheck must return `Service Unavailable` after draining") @@ -76,7 +76,7 @@ func Test_Handlers_Healthcheck_Drain_Undrain(t *testing.T) { w := httptest.NewRecorder() s.handleUndrain(w, req) resp := w.Result() - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck _, err := io.ReadAll(resp.Body) require.NoError(t, err) require.Equal(t, http.StatusOK, resp.StatusCode, "Must return `Ok` for calls to `/undrain`") @@ -88,7 +88,7 @@ func Test_Handlers_Healthcheck_Drain_Undrain(t *testing.T) { w := httptest.NewRecorder() s.handleReadinessCheck(w, req) resp := w.Result() - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck _, err := io.ReadAll(resp.Body) require.NoError(t, err) require.Equal(t, http.StatusOK, resp.StatusCode, "Healthcheck must return `Ok` after undraining")