yaml_util

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Lenient = CheckMode(false)
	Strict  = CheckMode(true)
)

Variables

This section is empty.

Functions

func CheckValid

func CheckValid[T any](content []byte, mode CheckMode) error

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

func SetValue(content []byte, optionPath string, optionValue string) ([]byte, error)

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

func YamlErrors(err error) []string

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).

Types

type CheckMode

type CheckMode bool

type RawNode added in v0.7.0

type RawNode struct{ *yaml.Node }

func (*RawNode) UnmarshalYAML added in v0.7.0

func (n *RawNode) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

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