yamlutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("no such node")
)

Functions

func AsYAML

func AsYAML(v interface{}) string

AsYAML marshals v into a string.

func FindNode

func FindNode(n *yaml.Node, path string) (*yaml.Node, error)

Get returns the node at the given path. The format of the path is similar to JSON path but simpler. It works only with mapping nodes. e.g. node1.node2 returns node2 and node1 must be a mapping node.

func IsEmpty

func IsEmpty(it interface{}) bool

IsEmpty returns true if it is nil, "", 0, or its lenghth is zero.

func MarshalJSONOmitEmpty

func MarshalJSONOmitEmpty(e interface{}) ([]byte, error)

MarshalJSONOmitEmpty mashals a given value as a JSON omitting all empty values

func MarshalJSONOmitEmptyIndented

func MarshalJSONOmitEmptyIndented(e interface{}) ([]byte, error)

MarshalJSONOmitEmptyIndented mashals a given value as a JSON omitting all empty values

func Merge

func Merge(a, b *yaml.Node) error

Merge tries to merge two yaml nodes a and b into a. It merges the nodes with the same kind.

func MergeMappingNode

func MergeMappingNode(a, b *yaml.Node) error

MergeMappingNode tries to merge two yaml nodes a and b into a. If it encounters incompatible nodes along the way, it returns error. We need to go through all content of a map and check whether the key is there. If yes, we merge it recursively, otherwise just append new key

func MergeSequenceNode

func MergeSequenceNode(a, b *yaml.Node) error

MergeSequenceNode attempts to merge two sequence nodes, a and b, into node a. Corresponding items are merged recursively. If the corresponding item is a scalar value, the item in 'a' is replaced with the corresponding item in 'b'. Any items in 'b' that come after the last item in 'a' are appended to 'a'.

func MergeYAML

func MergeYAML(v interface{}, contents ...string) (nodes []*yaml.Node, err error)

MergeYAML merges a list of given YAML contents.

func MustMarshalJSONOmitEmpty

func MustMarshalJSONOmitEmpty(e interface{}) string

MustMarshalJSONOmitEmpty is a sugar version of MustMarshalJSONOmitEmpty.

func NewDocument

func NewDocument() yaml.Node

NewDocument creates a new document node based on mapping.

func Parse

func Parse(reader io.Reader) (yaml.Node, error)

Parse is helper function that decodes yaml from io.Reader

func ParseFile

func ParseFile(f string) (yaml.Node, error)

ParseFile parses a YAML file and returns the root node.

func ParseString

func ParseString(s string) (yaml.Node, error)

ParseString parses a YAML document from a string.

func ReadYAMLFiles

func ReadYAMLFiles(v interface{}, files ...string) ([]*yaml.Node, error)

ReadYAMLFiles reads files in the given order and merge them. A later file will overwrite the previous yaml data.

func RemoveEmptyAny

func RemoveEmptyAny(e interface{}) (map[string]interface{}, error)

RemoveEmptyAny marshals a given e into a string, unmarshal back to a map and then remove empty objects.

func RemoveEmptyFromMap

func RemoveEmptyFromMap(it interface{}) interface{}

RemoveEmptyFromMap recursively removes empty values from a map.

func Write

func Write(doc yaml.Node, writer io.Writer) error

Write is helper function that writes yaml tree to io.Writer

Types

This section is empty.

Jump to

Keyboard shortcuts

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