Documentation
¶
Index ¶
- Constants
- func CheckValid[T any](content []byte, mode CheckMode) error
- func MarshalMap[K comparable, V any](m map[K]V, less func(K, K) bool) (*yaml.Node, error)
- func SetValue(content []byte, optionPath string, optionValue string) ([]byte, error)
- func YamlErrors(err error) []string
- type CheckMode
- type RawNode
Constants ¶
const ( Lenient = CheckMode(false) Strict = CheckMode(true) )
Variables ¶
This section is empty.
Functions ¶
func CheckValid ¶
CheckValid validates that the given yaml actually represents the type provided, and returns a non-nil error describing the problem if it doesn't. You need to explicitly provide the type to be checked:
CheckValid[MyCoolType](contents)
The strict flag governs whether the check will allow unknown fields.
func MarshalMap ¶ added in v0.7.0
func MarshalMap[K comparable, V any](m map[K]V, less func(K, K) bool) (*yaml.Node, error)
func SetValue ¶
SetValue upserts the value the content yaml to a given value, specified by a dotted path. For example, setting `foo.bar.baz` to `hello, world` is equivalent to upserting the following yaml:
foo:
bar:
baz: hello, world
This method will make a best effort to preserve comments, as per the `yaml` package's abilities. You may overwrite scalars, but you may not overwrite a non-scalar. You may also specify a path that doesn't exist in the source yaml, as long as none of the paths correspond to existing elements other than yaml mappings.
func YamlErrors ¶
YamlErrors returns the yaml.TypeError errors if the given err is a TypeError; otherwise, it just returns a single-element array of the given error's string (disregarding any wrapped errors).