yml

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ErrTerminate is a sentinel error that can be returned from a Walk function to terminate the walk.
	ErrTerminate = errors.Error("terminate")
)

Variables

This section is empty.

Functions

func ContextWithConfig

func ContextWithConfig(ctx context.Context, config *Config) context.Context

func CreateMapNode added in v0.2.1

func CreateMapNode(ctx context.Context, content []*yaml.Node) *yaml.Node

func CreateOrUpdateKeyNode

func CreateOrUpdateKeyNode(ctx context.Context, key string, keyNode *yaml.Node) *yaml.Node

func CreateOrUpdateMapNodeElement

func CreateOrUpdateMapNodeElement(ctx context.Context, key string, keyNode, valueNode, mapNode *yaml.Node) *yaml.Node

func CreateOrUpdateScalarNode

func CreateOrUpdateScalarNode(ctx context.Context, value any, valueNode *yaml.Node) *yaml.Node

func CreateOrUpdateSliceNode

func CreateOrUpdateSliceNode(ctx context.Context, elements []*yaml.Node, valueNode *yaml.Node) *yaml.Node

func CreateStringNode added in v1.0.0

func CreateStringNode(value string) *yaml.Node

func DeleteMapNodeElement

func DeleteMapNodeElement(ctx context.Context, key string, mapNode *yaml.Node) *yaml.Node

func EqualNodes added in v1.0.0

func EqualNodes(a, b *yaml.Node) bool

EqualNodes compares two yaml.Node instances for equality. It performs a deep comparison of the essential fields.

func GetMapElementNodes

func GetMapElementNodes(ctx context.Context, mapNode *yaml.Node, key string) (*yaml.Node, *yaml.Node, bool)

func NodeKindToString added in v0.2.2

func NodeKindToString(kind yaml.Kind) string

NodeKindToString returns a human-readable string representation of a yaml.Kind. This helper function is useful for creating more user-friendly error messages when dealing with YAML node kinds in error reporting.

func ResolveAlias added in v0.2.2

func ResolveAlias(node *yaml.Node) *yaml.Node

func Walk added in v0.1.4

func Walk(ctx context.Context, node *yaml.Node, visit VisitFunc) error

Walk will walk the yaml node structure and call the provided VisitFunc for each node in the document. TODO should key/index be passed for nodes that are children of maps/sequences?

Types

type Config

type Config struct {
	KeyStringStyle   yaml.Style   // The default string style to use when creating new keys
	ValueStringStyle yaml.Style   // The default string style to use when creating new nodes
	Indentation      int          // The indentation level of the document
	OutputFormat     OutputFormat // The output format to use when marshalling
	OriginalFormat   OutputFormat // The original input format, helps detect when we are changing formats
}

func GetConfigFromContext

func GetConfigFromContext(ctx context.Context) *Config

func GetConfigFromDoc

func GetConfigFromDoc(data []byte, doc *yaml.Node) *Config

type OutputFormat

type OutputFormat string
const (
	OutputFormatJSON OutputFormat = "json"
	OutputFormatYAML OutputFormat = "yaml"
)

type VisitFunc added in v0.1.4

type VisitFunc func(ctx context.Context, node, parent *yaml.Node, root *yaml.Node) error

VisitFunc represents a function that will be called for each node in the node structure. The functions receives the current node, any parent nodes, and the root node.

Jump to

Keyboard shortcuts

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