Step 01 of 06
Understand the idea
A service needs a clear way to start, show its version, and load its settings. In this lesson, you will connect the parts of Beacon and build one executable that can be run and supported by another person.
Key technical ideas
Build flags shape the artifact
go build -o bin/beacond ./cmd/beacond writes a named binary instead of a temporary run. Operators and scripts can refer to bin/beacond consistently. Build flags should not hide required runtime settings; they create the artifact, not the environment it runs in.
ldflags stamp identity
-ldflags "-X main.version=1.2.3" sets a string variable at link time. Stamping version, commit and build time lets a running service answer what code it is. During incidents, I think this pod has the fix is not a diagnostic method.
A version endpoint is operational evidence
GET /version should return the service name, version, commit and build time. It must not expose secrets or local paths. The endpoint lets load balancers, humans and future automation confirm exactly which artifact is serving traffic.
Thin main keeps ownership clear
main parses config, creates loggers, opens stores, builds handlers, starts the scheduler and handles shutdown. It should not contain SQL, probing logic or JSON contract mapping. Thin main is not less important; it is where the service becomes a process.
package main
import "fmt"
var version = "dev"
func main() { fmt.Println(version) }Build this with go build -ldflags "-X main.version=1.0.0" and the printed value changes without editing source. Beacon uses the same mechanism for /version.
Run versus build
| Command | Purpose | Output |
|---|---|---|
| Development | Temporary binary |
| Artifact | Reusable file |
| User tool | GOBIN path |
| Stamp metadata | String variables |
Technical terms used at work
Artifact — The built file delivered and run, such as
bin/beacond.ldflags — Linker flags passed by
go build, often used to set string variables.Version stamping — Embedding release identity into the binary at build time.
