Skip to content

Fix module name and let response recorder unwrap - #96

Merged
raeperd merged 10 commits into
mainfrom
fix/go-code-review
Nov 9, 2026
Merged

raeperd merged 10 commits into
mainfrom
fix/go-code-review

Conversation

@raeperd

@raeperd raeperd commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Go code review fixes, part 1 of 3. Dockerfile, .dockerignore, Makefile, and workflows are left for the follow-up PRs.

Net diff against main: 14 insertions, 21 deletions across 5 files.

Module name

go build with the module path github.com/raeperd/kickstart.go writes a binary named kickstart.go. The go tool then parses that binary as a source file, and go vet ./... and go build fail with illegal UTF-8 encoding until it is deleted. The Makefile avoids this with -o app, but anyone running go build directly hits it.

The module is renamed to github.com/raeperd/kickstart, matching the ghcr.io/raeperd/kickstart image name already in the Makefile. Nothing imports the module path, so the only other references were the goimports local prefix in .golangci.yml and the README rename step. The README step now says to replace raeperd/kickstart.go and then raeperd/kickstart, which covers go.mod, the lint config, and the image name in one instruction.

Response recorder

responseRecorder forwarded only SetWriteDeadline, so http.ResponseController could not reach Flush, Hijack, or SetReadDeadline. That blocks SSE, WebSocket upgrades, and streaming handlers in anything built on the template.

The SetWriteDeadline method is replaced by Unwrap, which is all http.ResponseController needs for every extension. Nothing else is intercepted. The trade-off: a panic after an explicit flush or a hijack is logged against the status the recorder saw rather than what the client received. That edge case did not seem worth extra methods in a template.

Question for review: #93 kept hijacking unsupported on purpose ("connection takeover ... bypass response accounting"). This PR assumes the goal was log accuracy rather than a hard policy. If hijacking should stay blocked, Unwrap can be dropped again and only SetReadDeadline added next to SetWriteDeadline.

Debug endpoints: unchanged

pprof and expvar stay on the service port, as on main. A separate DEBUG_PORT listener and a DEBUG opt-in flag were both tried on this branch and reverted: each added configuration and code to a template that aims to stay minimal. Restricting /debug/ is left to the deployment, and the README feature line now says so.

Testing

  • make (build, golangci-lint v2.11.4, deadcode, go test -shuffle=on -race) passes with Go 1.26.1. Statement coverage is 88.4%, same as main.
  • Changed test: the recorder case now sets a read deadline, a write deadline, and flushes through http.ResponseController over a real connection.

The module path github.com/raeperd/kickstart.go made go build write a
binary named kickstart.go, which the go tool then parsed as a source
file and failed vet and build until it was deleted. Drop the .go suffix,
matching the ghcr.io/raeperd/kickstart image name, and update the
goimports local prefix and the README rename step.
The recorder only forwarded SetWriteDeadline, so handlers could not
flush, hijack, or set a read deadline through http.ResponseController,
and type assertions for http.Flusher and http.Hijacker failed. Expose
Unwrap for deadlines and intercept Flush and Hijack so the recorded
status still matches what the client received: a flush commits the
implicit 200, and a hijacked connection records no status and stops
recovery from writing a 500 into it.
The debug handlers were mounted on the service port, so every
deployment exposed pprof and expvar wherever the service was reachable.
Serve them from a second listener bound to DEBUG_PORT, with the default
left unset so nothing is exposed unless asked for. The second server
starts and shuts down alongside the service server, and a failed debug
bind stops the service the same way a failed service bind does.
TestMain runs main when KICKSTART_TEST_MAIN is set, and TestMainExit
spawns the test binary that way to check the non-zero exit and stderr
message for an invalid PORT and the clean exit after SIGINT. Statement
coverage goes from 90.5% to 95.7%.
@coveralls

coveralls commented Nov 4, 2026 •

Copy link
Copy Markdown

Coverage Status

Coverage is 88.608% — fix/go-code-review into main. No base build found for main.

A separate DEBUG_PORT server needed its own lifecycle, shutdown, and
bind-failure handling plus tests for all of it. Keep pprof and expvar on
the service mux, registered only when DEBUG is set, so the default
exposes nothing and the template stays one server.
Replacing raeperd/kickstart after raeperd/kickstart.go covers go.mod,
the goimports prefix, and the image name in one instruction.
Intercepting Flush and Hijack only sharpened the access log for a panic
after a flush or hijack, at the cost of four methods and a flag. Expose
Unwrap and let http.ResponseController handle Flush, Hijack, and both
deadlines.
@raeperd raeperd changed the title Fix module name, response recorder pass-through, and debug endpoint exposure Fix module name, recorder Unwrap, and default-on debug endpoints Nov 4, 2026
@raeperd raeperd changed the title Fix module name, recorder Unwrap, and default-on debug endpoints Fix module name, recorder Unwrap, and default-off debug endpoints Nov 4, 2026
Gating pprof and expvar behind DEBUG added a flag, a parameter, and a
README paragraph to a template that aims to stay minimal. Restore the
unconditional /debug/ route; restricting it is a deployment concern.
@raeperd raeperd changed the title Fix module name, recorder Unwrap, and default-off debug endpoints Fix module name and let response recorder unwrap Nov 9, 2026
@raeperd
raeperd marked this pull request as ready for review November 9, 2026 14:57
@raeperd
raeperd merged commit c60be87 into main Nov 9, 2026
3 checks passed
@raeperd
raeperd deleted the fix/go-code-review branch November 9, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants