Add snapshotted mapping configuration sources
This commit is contained in:
11
source.go
11
source.go
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// Source is an opaque configuration input. Construct sources with File,
|
||||
// Filesystem.File, Bytes, Reader, or NoSource; the zero value is invalid.
|
||||
// Filesystem.File, Bytes, Reader, Mapping, or NoSource; the zero value is invalid.
|
||||
type Source struct{ value engine.Source }
|
||||
|
||||
// Filesystem is a reusable opaque namespace for a caller-owned fs.FS. Copies
|
||||
@@ -38,6 +38,15 @@ func Bytes(label string, data []byte) Source { return Source{value: engine.Bytes
|
||||
// Copies of the returned Source share the same single-use claim.
|
||||
func Reader(label string, input io.Reader) Source { return Source{value: engine.Reader(label, input)} }
|
||||
|
||||
// Mapping snapshots supported built-in values immediately. A nil root map is
|
||||
// invalid; an empty map is a valid empty document. Values may be nil, built-in
|
||||
// scalars, []any, or map[string]any recursively. Unsupported values and cycles
|
||||
// are reported when the source is consumed. Label must be nonempty and safe to
|
||||
// display. Later caller mutation cannot change the captured document.
|
||||
func Mapping(label string, values map[string]any) Source {
|
||||
return Source{value: engine.Mapping(label, values)}
|
||||
}
|
||||
|
||||
// NoSource explicitly selects a defaults-only input. It creates no source record.
|
||||
func NoSource() Source { return Source{value: engine.NoSource()} }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user