Extract server wiring (repositories, handlers, routes) #160

Closed
opened 2026-10-07 11:49:54 +00:00 by aniram · 0 comments
Owner

cmd/web/main.go should only load config, connect the DB, build the server and run it. Move repository construction, handler construction and mainMux.HandleFunc(...) calls into internal/server (e.g. server.New(deps) http.Handler).

Also fix these:

The section comments are swapped: /** handlers / sits above repositories and / repositories **/ above handlers.
*templates is dereferenced and copied by value into every handler. template.Template should not be copied (go vet will flag it). Pass the pointer instead and update the handler constructors.
/test and /error routes use fmt.Printf for errors. Use the logger.
The //TODO: use custom log function next to log.Fatalf can be resolved here.

Acceptance criteria:

  • main.go is under ~40 lines.
  • go vet ./... passes with no copylocks warnings.
cmd/web/main.go should only load config, connect the DB, build the server and run it. Move repository construction, handler construction and mainMux.HandleFunc(...) calls into internal/server (e.g. server.New(deps) http.Handler). Also fix these: The section comments are swapped: /** handlers **/ sits above repositories and /** repositories **/ above handlers. *templates is dereferenced and copied by value into every handler. template.Template should not be copied (go vet will flag it). Pass the pointer instead and update the handler constructors. /test and /error routes use fmt.Printf for errors. Use the logger. The //TODO: use custom log function next to log.Fatalf can be resolved here. Acceptance criteria: - main.go is under ~40 lines. - go vet ./... passes with no copylocks warnings.
aniram added this to the 2027.1 milestone 2026-10-07 11:50:24 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
overdrives/chambersbr#160
No description provided.