Documentation
¶
Overview ¶
This package provides some basic functions for working with yaml nodes. The assumption is to never directly encode/decode yaml. Instead, we'll convert to/from interface{}.
Index ¶
- func Append(targetArray *yaml.Node, values ...*yaml.Node) error
- func AppendSlice(targetArray *yaml.Node, values []*yaml.Node) error
- func CopyNode(node *yaml.Node) *yaml.Node
- func FindFieldKeyIndex(targetObject *yaml.Node, key string) int
- func FindFieldValueIndex(targetObject *yaml.Node, key string) int
- func FromObject(data map[string]interface{}) (*yaml.Node, error)
- func GetFieldValue(targetObject *yaml.Node, key string) *yaml.Node
- func NewArray() *yaml.Node
- func NewObject() *yaml.Node
- func NewString(value string) *yaml.Node
- func RemoveField(targetObject *yaml.Node, key string)
- func RemoveFieldByIdx(targetObject *yaml.Node, idx int)
- func SetFieldValue(targetObject *yaml.Node, key string, value *yaml.Node)
- func ToArray(data *yaml.Node) ([]interface{}, error)
- func ToObject(data *yaml.Node) (map[string]interface{}, error)
- type YamlArrayIterator
- type YamlArrayMatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
func Append(targetArray *yaml.Node, values ...*yaml.Node) error
Append adds the given values to the end of the targetArray. If no values are given, then nothing is done. If targetArray is nil or not a sequence node, then an error is returned. If any of the values are nil, then an error is returned (and the array remains unchanged).
func AppendSlice ¶
func AppendSlice(targetArray *yaml.Node, values []*yaml.Node) error
AppendSlice appends all entries in a slice to the end of the targetArray. If targetArray is nil or not a sequence node, then an error is returned. If the slice is nil, then nothing is done. If any of the values in the slice are nil, then an error is returned (and the array remains unchanged).
func CopyNode ¶
func CopyNode(node *yaml.Node) *yaml.Node
CopyNode creates a deep copy of the given node.
func FindFieldKeyIndex ¶
FindFieldKeyIndex returns the index of the Node that contains the object-Key in the targets Content array. If the key is not found, it returns -1.
func FindFieldValueIndex ¶
FindFieldValueIndex returns the index of the Node that contains the object-Value in the targets Content array. If the value is not found, it returns -1.
func FromObject ¶
FromObject converts the given map[string]interface{} to an yaml node (map).
func GetFieldValue ¶
func GetFieldValue(targetObject *yaml.Node, key string) *yaml.Node
GetFieldValue returns the value of the given key in the targetObject. If the key is not found, then nil is returned.
func RemoveField ¶
func RemoveField(targetObject *yaml.Node, key string)
RemoveField removes the given key and its value from the targetObject if it exists.
func RemoveFieldByIdx ¶
func RemoveFieldByIdx(targetObject *yaml.Node, idx int)
RemoveFieldByIdx removes the key (by its index) and its value from the targetObject.
func SetFieldValue ¶
func SetFieldValue(targetObject *yaml.Node, key string, value *yaml.Node)
SetFieldValue sets/overwrites the value of the given key in the targetObject to the given value. If value is nil, then the key is removed from the targetObject if it exists.
Types ¶
type YamlArrayIterator ¶
YamlArrayIterator is a type of function returned by Search. On each call, it returns the next matching node in the targetArray. If no more matches are found, then nil is returned. The second return value is the index of the node in the targetArray.
func Search ¶
func Search(targetArray *yaml.Node, match YamlArrayMatcher) YamlArrayIterator
Search returns a YamlArrayIterator function that can be called repeatedly to find the next matching node in the targetArray. If no more matches are found, then nil is returned. The search is resilient against changing the targetArray while searching. The YamlArrayMatcher function is called with each (non-nil) node in the targetArray. If the match function returns true, then the node is returned. If the match function returns false, then the next node is checked. If the match function returns an error, then the search is aborted and the error is returned (calling again returns the same error).
type YamlArrayMatcher ¶
YamlArrayMatcher is a type of function passed to Search. To match a node against the search criteria, the function should return true if it matches.