Shows how to use explicit codecs for both reading and writing configuration.
WithFileAs(path, codec.JSON): load a JSON file explicitly (no extension guessing)WithFileAs(path, codec.TOML): load a TOML override on top of itWithFileDumperAs(path, codec.YAML): dump the merged effective configuration to a YAML file
app.json: base configuration in JSON formatoverrides.toml: overrides in TOML format;listen.porthere wins over the JSON valueeffective-config.yaml: written onDump(not committed)
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.
cd examples/codecs && go test -vWithFileAslets you load any format regardless of file extension.- Source order is priority order. Later sources win on conflicting keys.
WithFileDumperAswrites the fully merged map, not the last-loaded file. Useful for debugging or snapshotting effective configuration.