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 /version HTTP endpoint that returns build metadata injected at compile time via -ldflags.
Acceptance criteria
GET /version returns 200 OK with Content-Type: application/json
Response body: {"version": "<git-sha>", "built_at": "<RFC3339 UTC timestamp>"}
When built without ldflags (local dev), values fall back to "dev" and "unknown" respectively
The endpoint is registered in main.go alongside /healthz
task build injects the real values automatically via ldflags
Default values are "dev" and "unknown" when not injected
Handler returns 200 with valid JSON containing version and built_at keys
Branch
feat/version-endpoint from main
Out of scope
No auth on the endpoint (consistent with /healthz)
No structured HTML response — JSON only
No __PROJECT_NAME__ placeholder substitution needed (buildinfo package name is fixed)
Created via git-mcp on behalf of @mathiasbq
## 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 `/version` HTTP endpoint that returns build metadata injected at compile time via `-ldflags`.
## Acceptance criteria
- `GET /version` returns `200 OK` with `Content-Type: application/json`
- Response body: `{"version": "<git-sha>", "built_at": "<RFC3339 UTC timestamp>"}`
- When built without ldflags (local dev), values fall back to `"dev"` and `"unknown"` respectively
- The endpoint is registered in `main.go` alongside `/healthz`
- `task build` injects the real values automatically via ldflags
- A test covers at least the `dev` fallback case
## Implementation notes
### Package
Add `internal/buildinfo/buildinfo.go`:
```go
package buildinfo
var (
Version = "dev"
BuiltAt = "unknown"
)
```
### Handler
Register in `main.go`:
```go
mux.HandleFunc("/version", buildinfo.Handler)
```
Where `Handler` is a simple `http.HandlerFunc` on the `buildinfo` package that marshals the two vars to JSON.
### Taskfile ldflags
Update the `build` task in `Taskfile.yml`:
```yaml
build:
desc: Build the binary
deps: [generate]
vars:
SHA:
sh: git rev-parse --short HEAD
BUILT_AT:
sh: date -u +%Y-%m-%dT%H:%M:%SZ
cmds:
- go build
-ldflags "-X __MODULE_PATH__/internal/buildinfo.Version={{.SHA}} -X __MODULE_PATH__/internal/buildinfo.BuiltAt={{.BUILT_AT}}"
-o bin/__PROJECT_NAME__
./cmd/__PROJECT_NAME__
```
### Test
Add `internal/buildinfo/buildinfo_test.go` covering:
- Default values are `"dev"` and `"unknown"` when not injected
- Handler returns `200` with valid JSON containing `version` and `built_at` keys
## Branch
`feat/version-endpoint` from `main`
## Out of scope
- No auth on the endpoint (consistent with `/healthz`)
- No structured HTML response — JSON only
- No `__PROJECT_NAME__` placeholder substitution needed (buildinfo package name is fixed)
---
_Created via git-mcp on behalf of @mathiasbq_
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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