yaml

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeField added in v0.9.0

func DecodeField(node *yaml.Node, path string, out any) error

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 SetStringsInBytes

func SetStringsInBytes(
	inBytes []byte,
	changes map[string]string,
) ([]byte, error)

SetStringsInBytes returns a copy of the provided bytes with the changes specified by the changes map applied. The changes map maps keys to new values. 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 SetStringsInFile

func SetStringsInFile(file string, changes map[string]string) error

SetStringsInFile overwrites the specified file with the changes specified by the changes map applied. The changes map maps keys to new values. 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 added in v0.9.0

func UpdateField(node *yaml.Node, key string, value any) error

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 added in v0.9.0

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 added in v0.9.0

func (e FieldNotFoundErr) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL