yamlnode

package
v0.0.0-...-87586f8 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package yamlnode allows for manipulation of YAML nodes using a dotted-path syntax.

Examples of dotted-path syntax:

  • a.map.key
  • b.items[1]

When using Set or Append, an optional qualifier `?` can be used in a path element to indicate that the node is conditionally present, and should be created if not present. A preceding bracket-pair, `[]`, can be used to indicate that a sequence node should be created.

Optional qualifier examples:

  • a?.map.key - if 'a' is not present, it will be created
  • a.map?.key - if 'map' is not present, it will be created
  • b.items[]? - if 'items' is not present, it will be created as a sequence

The special characters in a dotted-path syntax are:

  • `.` (dot) - separates key elements
  • `[` (open bracket) - used in sequences
  • `]` (close bracket) - used in sequences
  • `?` (question mark) - optional qualifier
  • `"` (double quote) - used to indicate a quoted-string

If these special characters are part of a key, the key can be surrounded as a quoted-string using `"` (double quotes) to indicate their literalness. If a `"` (double-quote) character is also part of the key, a preceding backslash `\"` may be used to escape it.

Quoted-string examples:

  • "esc.ape.d" -> esc.ape.d
  • "\"hello\"..[world]" -> "hello"..[world]

Index

Constants

This section is empty.

Variables

View Source
var ErrNodeNotFound = errors.New("node not found")
View Source
var ErrNodeWrongKind = errors.New("unexpected node kind")

ErrNodeWrongKind is returned when the node kind is not as expected. This error may be useful to detect nodes that have multiple possible kinds and need to be handled specially.

Functions

func Append

func Append(root *yaml.Node, path string, node *yaml.Node) error

Append appends a node to the sequence node at the given path. If the node at the path is not a sequence node, ErrNodeWrongKind is returned.

An optional qualifier `?` can be used automatically create node(s) that are conditionally present; a preceding bracket-pair, `[]`, is used to indicate sequences.

Examples:

  • a?.map.items - if 'a' is not present, it will be created
  • b.items[]? - if 'items' is not present, it will be created as a sequence

func Encode

func Encode(value interface{}) (*yaml.Node, error)

Encode encodes a value into a YAML node.

func Find

func Find(root *yaml.Node, path string) (*yaml.Node, error)

Find retrieves a node at the given path.

Examples of dotted-paths:

  • a.map.key
  • b.items[1]

func Set

func Set(root *yaml.Node, path string, value *yaml.Node) error

Set sets the node at the path to the provided value.

An optional qualifier `?` can be used automatically create node(s) that are conditionally present.

Examples:

  • a?.map.key - if 'a' is not present, it will be created
  • a.map?.key - if 'map' is not present, it will be created

Types

This section is empty.

Jump to

Keyboard shortcuts

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