yml

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 6 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 CreateBoolNode added in v1.3.0

func CreateBoolNode(value bool) *yaml.Node

func CreateFloatNode added in v1.3.0

func CreateFloatNode(value float64) *yaml.Node

func CreateIntNode added in v1.3.0

func CreateIntNode(value int64) *yaml.Node

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 NodeTagToString added in v1.7.5

func NodeTagToString(tag string) string

func ResolveAlias added in v0.2.2

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

func TypeToYamlTags added in v1.7.5

func TypeToYamlTags(typ reflect.Type) []string

TypeToYamlTags returns all acceptable YAML tags for a given reflect.Type. For numeric types, both the specific tag and !!str are acceptable since YAML can decode string representations of numbers. For pointer types, !!null is also acceptable.

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
	IndentationStyle IndentationStyle // The indentation style of the document valid for JSON only
	OutputFormat     OutputFormat     // The output format to use when marshalling
	OriginalFormat   OutputFormat     // The original input format, helps detect when we are changing formats
	TrailingNewline  bool             // Whether the original document had a trailing newline
}

func GetConfigFromContext

func GetConfigFromContext(ctx context.Context) *Config

func GetConfigFromDoc

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

func GetDefaultConfig added in v1.11.3

func GetDefaultConfig() *Config

type IndentationStyle added in v1.11.0

type IndentationStyle string
const (
	IndentationStyleSpace IndentationStyle = "space"
	IndentationStyleTab   IndentationStyle = "tab"
)

func (IndentationStyle) ToIndent added in v1.11.0

func (i IndentationStyle) ToIndent() string

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