feat: add /version endpoint with build-time SHA and timestamp #1
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Every service bootstrapped from this template should be able to report its own build identity at runtime. This is useful for health dashboards, deploy verification, and debugging — "which version is actually running right now?"
Task
Add a
/versionHTTP endpoint that returns build metadata injected at compile time via-ldflags.Acceptance criteria
GET /versionreturns200 OKwithContent-Type: application/json{"version": "<git-sha>", "built_at": "<RFC3339 UTC timestamp>"}"dev"and"unknown"respectivelymain.goalongside/healthztask buildinjects the real values automatically via ldflagsdevfallback caseImplementation notes
Package
Add
internal/buildinfo/buildinfo.go:Handler
Register in
main.go:Where
Handleris a simplehttp.HandlerFuncon thebuildinfopackage that marshals the two vars to JSON.Taskfile ldflags
Update the
buildtask inTaskfile.yml:Test
Add
internal/buildinfo/buildinfo_test.gocovering:"dev"and"unknown"when not injected200with valid JSON containingversionandbuilt_atkeysBranch
feat/version-endpointfrommainOut of scope
/healthz)__PROJECT_NAME__placeholder substitution needed (buildinfo package name is fixed)Created via git-mcp on behalf of @mathiasbq