refactor(v2/httpserver): remove Router interface, accept http.Handler
Context
The chi router discussion reached consensus:
- Don't abstract the router. Hyrum's Law makes swappability moot in practice.
- Modern stdlib is sufficient for most services. Chi is fine when needed.
- LabKit's value is middleware (tracing, access logging, correlation IDs), not routing.
- Define the minimum, not the implementation.
The decision is formalized in ADR 001 (handbook !18825).
What's in this MR?
Remove the Router interface from v2/httpserver. Consumers bring their own router (stdlib http.ServeMux, chi, or any http.Handler) and pass it via Config.Handler.
-
Remove
Routerinterface (17 methods),chiRouteradapter,newDefaultRouter(),Server.Router()accessor -
Replace
Config.Router RouterwithConfig.Handler http.Handler -
Simplify
URLParamto delegate tor.PathValue()(Go 1.22+, works with both stdlib and chi v5.1+) -
Add
SetRoutePattern/RoutePatterncontext helpers for low-cardinality tracing span names. Uses a mutable holder pattern so inner middleware can communicate the route pattern back to the outer tracing middleware. -
Remove
github.com/go-chi/chi/v5dependency fromv2/go.mod - Rewrite tests, docs, examples for the new handler-based API
Proof of work
$ cd v2 && go test ./httpserver/ -count=1
ok gitlab.com/gitlab-org/labkit/v2/httpserver 0.534s
$ cd v2 && go test ./... -count=1
ok gitlab.com/gitlab-org/labkit/v2/app 0.501s
ok gitlab.com/gitlab-org/labkit/v2/httpserver 2.096s
# ... all packages pass
$ ./scripts/golangci-lint.sh
# clean
Related
- Closes gitlab-org/quality/quality-engineering/team-tasks#4294 (closed)
- Relates to gitlab-org/quality/quality-engineering/team-tasks#4311
- Relates to gitlab-com/content-sites/handbook!18825 (ADR 001)
Edited by Doug Barrett