Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: "2"
linters:
enable-all: true
disable:
- cyclop
- forbidigo
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocritic
Expand Down Expand Up @@ -39,7 +39,6 @@ linters:
#
# Disabled because deprecated:
#
- tenv

linters-settings:
#
Expand Down Expand Up @@ -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$
40 changes: 40 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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`.

## 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.
- `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.

## 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).
6 changes: 3 additions & 3 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions httpserver/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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`")
Expand All @@ -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")
Expand All @@ -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`")
Expand All @@ -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")
Expand Down
Loading