config: Merge with per-value origins; configcmd: UnknownKeysNode
config.Merge(sources...) overlays explicit, ordered sources with the LoadMerged rules (LoadMerged now uses the same code) and returns the origin of every leaf, for a "config show" that says where each value is set. config.ReadFile reads one file as a mapping, Resolver.Paths() exposes the core/paths resolver (e.g. DataDir for defaults). configcmd.UnknownKeysNode checks one section of a parsed document. Needed by the yamase family's layered configuration (yamase ADR-0074). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b7f7ba6b36
commit
185211e304
7 files changed
+262
-13
No files matched your search
@@ -250,6 +250,27 @@ LOCALAPPDATA/APPDATA/PROGRAMDATA layering `core/paths` already resolves.
|
||||
layer can write `key: null` to intentionally unset a lower layer's
|
||||
value).
|
||||
|
||||
### Merging your own layers, with origins
|
||||
|
||||
An application whose layers are not one file name per directory (the
|
||||
yamase family reads a shared `yamase.yaml`, one section of it, and a
|
||||
per-program file in every tier) builds its own ordered list and merges
|
||||
it with the same rules:
|
||||
|
||||
```go
|
||||
data, err := config.ReadFile(path) // one file as a mapping
|
||||
merged, origins := config.Merge(
|
||||
config.Source{Name: "/etc/app/shared.yaml", Data: shared},
|
||||
config.Source{Name: "/etc/app/app.yaml", Data: data},
|
||||
)
|
||||
// origins["tls.cert-file"] == the Name of the source that set it
|
||||
```
|
||||
|
||||
`Origins` maps every leaf's dotted key to the source it came from (a
|
||||
list is one leaf), for a "config show" that says where each value is
|
||||
set. `Resolver.Paths()` returns the underlying `core/paths` resolver,
|
||||
e.g. for a default derived from `DataDir()`.
|
||||
|
||||
### Environment expansion
|
||||
|
||||
String values may reference `${VAR}` or `$VAR` (enabled by default,
|
||||
|
||||
Reference in new issue
Block a user