command
Version:
v0.5.0
Opens a new window with list of versions in this module.
Published: May 17, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Embedded defaults (WithContent)
Bake default values into your binary, override them with a file, then let environment variables win last.
Sources are merged in order -- later values replace earlier ones:
WithContent -- small YAML defaults embedded in Go code
WithFile("overrides.yaml") -- checked-in overrides
WithEnv("DEMO_") -- highest precedence
Run
cd examples/defaults
DEMO_SERVER_PORT=9999 go run .
Expected output: server.name=from-file server.port=9999
server.name comes from overrides.yaml (replaced the baked-in default)
server.port comes from the DEMO_SERVER_PORT env var (replaced the file value of 7000)
Tests
cd examples/defaults && go test -v
Key ideas
- Merge order matters -- sources added later override earlier ones on the same key.
- Embedded defaults --
WithContent takes a []byte and a codec, so you can use go:embed or a literal.
- Three layers -- defaults, file, environment is a common production pattern.
Documentation
¶
Package main shows merge order: baked-in defaults, then file, then env.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.