command
Version:
v0.12.0
Opens a new window with list of versions in this module.
Published: May 20, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 6
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Codecs example
Shows how to use explicit codecs for both reading and writing configuration.
What it shows
WithFileAs(path, codec.JSON): load a JSON file explicitly (no extension guessing)
WithFileAs(path, codec.TOML): load a TOML override on top of it
WithFileDumperAs(path, codec.YAML): dump the merged effective configuration to a YAML file
Files
app.json: base configuration in JSON format
overrides.toml: overrides in TOML format; listen.port here wins over the JSON value
effective-config.yaml: written on Dump (not committed)
Run
cd examples/codecs && go run .
Output: app=formats-demo listen.port=4000 meta.region=local
A file effective-config.yaml is also written with the fully merged state.
Tests
cd examples/codecs && go test -v
Key ideas
WithFileAs lets you load any format regardless of file extension.
- Source order is priority order. Later sources win on conflicting keys.
WithFileDumperAs writes the fully merged map, not the last-loaded file. Useful for debugging or snapshotting effective configuration.
Documentation
¶
Package main shows codec usage end-to-end: JSON + TOML as input sources,
merged YAML written out via WithFileDumperAs.
Sources (lowest to highest priority):
- app.json — loaded with WithFileAs and codec.JSON
- overrides.toml — loaded with WithFileAs and codec.TOML (wins on conflicts)
After Load, Dump writes the merged state to effective-config.yaml.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.