refactor: config consolidation + Server type extraction #108

Merged
lerko merged 2 commits from refactor/config-server into main 2026-06-11 20:42:32 +00:00
Owner

Summary

Phase 5b of the review-findings backlog — two independent architectural cleanups.

Commit 1 — config consolidation:

  • New cmd/uptop/config.go with appConfig struct + parseConfig()
  • All 25 UPTOP_* env vars parsed in one place with defaults
  • runServe() simplified: cfg := parseConfig() up front, no scattered os.Getenv calls
  • serverConfig() method builds server.ServerConfig from the consolidated struct
  • Uniform flag > env > default precedence for port/db-type/dsn

Commit 2 — Server type extraction:

  • 328-line Start() god function → Server struct with 11 named handler methods
  • routes() registers all endpoints, middleware() chain applied once
  • requireAuth() helper replaces repeated auth checks
  • Start() kept as convenience wrapper so existing callers work unchanged
  • Each handler independently readable and testable

Test plan

  • go test -race ./... — all pass
  • golangci-lint — 0 issues
  • No os.Getenv("UPTOP_") in runServe body (only in parseConfig + other subcommands)
  • No inline handler closures in server.go (all named methods)
## Summary Phase 5b of the review-findings backlog — two independent architectural cleanups. **Commit 1 — config consolidation:** - New `cmd/uptop/config.go` with `appConfig` struct + `parseConfig()` - All 25 `UPTOP_*` env vars parsed in one place with defaults - `runServe()` simplified: `cfg := parseConfig()` up front, no scattered `os.Getenv` calls - `serverConfig()` method builds `server.ServerConfig` from the consolidated struct - Uniform flag > env > default precedence for port/db-type/dsn **Commit 2 — Server type extraction:** - 328-line `Start()` god function → `Server` struct with 11 named handler methods - `routes()` registers all endpoints, `middleware()` chain applied once - `requireAuth()` helper replaces repeated auth checks - `Start()` kept as convenience wrapper so existing callers work unchanged - Each handler independently readable and testable ## Test plan - [x] `go test -race ./...` — all pass - [x] `golangci-lint` — 0 issues - [x] No `os.Getenv("UPTOP_")` in runServe body (only in parseConfig + other subcommands) - [x] No inline handler closures in server.go (all named methods)
lerko added 2 commits 2026-06-11 20:38:03 +00:00
New cmd/uptop/config.go with appConfig struct + parseConfig() that
reads all 25 UPTOP_* env vars in one place with defaults. Replaces
~120 lines of scattered os.Getenv calls in runServe.

runServe now reads cfg := parseConfig() up front. ServerConfig
built via cfg.serverConfig(). Uniform flag > env > default
precedence for port/db-type/dsn via flag defaults from config.
refactor(server): extract Server type with named handler methods
CI / test (pull_request) Successful in 1m53s
CI / lint (pull_request) Successful in 1m21s
CI / vulncheck (pull_request) Successful in 1m2s
ba4465daa2
Replace the 328-line Start() god function with a Server struct +
11 named handler methods. Routes registered in routes(), middleware
applied in one place.

Start() kept as a convenience wrapper (NewServer + Start) so
existing callers don't need to change unless they want the Server
reference.

Each handler is now independently readable and testable without
parsing a 300-line closure nest.
lerko merged commit ba4465daa2 into main 2026-06-11 20:42:32 +00:00
lerko deleted branch refactor/config-server 2026-06-11 20:42:32 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lerkolabs/uptop#108