yamlutils

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package yamlutils - Utilities to read yml files like if using xpath

Index

Constants

This section is empty.

Variables

View Source
var ErrExtraElementsInPath = fmt.Errorf("extra elements in path")

ErrExtraElementsInPath - Indicates when there is a final match and there are remaining path elements.

View Source
var ErrInvalidChildTypeKeyValue = fmt.Errorf("invalid child type, must be 'key: value'")

ErrInvalidChildTypeKeyValue - The child type is invalid.

View Source
var ErrInvalidIndex = fmt.Errorf("invalid index")

ErrInvalidIndex - The given index is invalid.

View Source
var ErrInvalidParentType = fmt.Errorf("invalid parent type, must be list or key/value")

ErrInvalidParentType - The parent type is invalid.

View Source
var ErrMapKeyNotFound = fmt.Errorf("map key not found")

ErrMapKeyNotFound - Key not in config.

View Source
var ErrNotAnIndex = fmt.Errorf("not an index")

ErrNotAnIndex - The given path is not a numerical index and the element is of type slice/array.

View Source
var Logger = log.New(ioutil.Discard, "yamlutils ", log.LstdFlags)

Logger - Custom lib logger

Functions

func AddChild

func AddChild(m *interface{}, child string) error

func AddChildToTree

func AddChildToTree(parent *interface{}, current *interface{}, p []string, child string) error
func NavigateTree(include bool, m interface{}, p []string) (interface{}, []string, error)

NavigateTree allows you to define a path string to traverse a tree composed of maps and arrays. To navigate through slices/arrays use a numerical index, for example: [path to array 1] When include is true, the returned map will have the key as part of it.

Types

type YML

type YML struct {
	Tree interface{}
}

YML object

func NewFromFile

func NewFromFile(filename string) (*YML, error)

NewFromFile returns a pointer to a YML object from a file.

func NewFromReader

func NewFromReader(reader io.Reader) (*YML, error)

NewFromReader returns a pointer to a YML object from an io.Reader.

func NewFromString

func NewFromString(str string) (*YML, error)

NewFromString - returns a pointer to a YML object from a string.

func (*YML) AddString

func (y *YML) AddString(keys []string, input string) (string, error)

func (*YML) GetString

func (y *YML) GetString(include bool, keys []string) (string, error)

GetString returns a string designated by path. Path is a string with elements separated by /. Array indexes are given as a number. For example: "level1/level2/3/level4"

Jump to

Keyboard shortcuts

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