Documentation
¶
Index ¶
- func DecodeField(node *yaml.Node, path string, out any) error
- func QuoteIfNecessary(val any) any
- func SetValuesInBytes(inBytes []byte, updates []Update) ([]byte, error)
- func SetValuesInFile(file string, updates []Update) error
- func UpdateField(node *yaml.Node, key string, value any) error
- type FieldNotFoundErr
- type Update
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeField ¶
DecodeField retrieves the value at the specified path in the YAML document and decodes it into the provided value. The path is specified using a dot-separated string, similar to the UpdateField function.
func QuoteIfNecessary ¶
QuoteIfNecessary takes a value and returns it as-is if it is not a string. If it is a string, it ascertains whether a YAML parser would interpret it as another type. If so, it returns the string with additional quotes around it. If not, it returns the string as-is.
func SetValuesInBytes ¶
SetValuesInBytes returns a copy of the provided bytes with the changes specified by Updates applied. Keys are of the form <key 0>.<key 1>...<key n>. Integers may be used as keys in cases where a specific node needs to be selected from a sequence. An error is returned for any attempted update to a key that does not exist or does not address a scalar node. Importantly, all comments and style choices in the input bytes are preserved in the output.
func SetValuesInFile ¶
SetValuesInFile overwrites the specified file with the changes specified by the the list of Updates. Keys are of the form <key 0>.<key 1>...<key n>. Integers may be used as keys in cases where a specific node needs to be selected from a sequence. An error is returned for any attempted update to a key that does not exist or does not address a scalar node. Importantly, all comments and style choices in the input bytes are preserved in the output.
func UpdateField ¶
UpdateField updates the value of a field in a YAML document. The field is specified using a dot-separated path. If the field does not exist, it is created. The YAML node is modified in place, preserving comments and style.
The value parameter can be any Go value that can be marshaled to YAML using the yaml package. This includes basic types (string, int, bool, etc.), maps, slices, and structs.
Types ¶
type FieldNotFoundErr ¶
type FieldNotFoundErr struct {
// contains filtered or unexported fields
}
FieldNotFoundErr is an error type that is returned when a field is not found in the YAML document.
func (FieldNotFoundErr) Error ¶
func (e FieldNotFoundErr) Error() string
Error implements the error interface.