tree

package
v0.0.0-...-b438bb3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const PathSeparator = "."

PathSeparator delimits single path elements.

Variables

This section is empty.

Functions

func PathContains

func PathContains(path, subPath string) bool

PathContains returns whether the path contains the subPath.

func PathJoin

func PathJoin(elem ...string) string

PathJoin creates a new path from several path strings.

func PathSplit

func PathSplit(path string) []string

PathSplit splits a path into its elements.

Types

type ErrCannotModify

type ErrCannotModify struct {
	Value, Type string
}

ErrCannotModify is returned when trying to write into a nil or non pointer value.

func (*ErrCannotModify) Error

func (e *ErrCannotModify) Error() string

type ErrElementNotFound

type ErrElementNotFound struct {
	Path string
}

ErrElementNotFound is returned if the element couldn't be found at the given path.

func (*ErrElementNotFound) Error

func (e *ErrElementNotFound) Error() string

type ErrKeyIsNotString

type ErrKeyIsNotString struct {
	Key, Type string
}

ErrKeyIsNotString is returned if a key of a map is not of type string.

func (*ErrKeyIsNotString) Error

func (e *ErrKeyIsNotString) Error() string

type ErrPathInsideValue

type ErrPathInsideValue struct {
	Path string
}

ErrPathInsideValue is returned if a path is pointing inside a value.

func (*ErrPathInsideValue) Error

func (e *ErrPathInsideValue) Error() string

type ErrPathInvalid

type ErrPathInvalid struct {
	Path   string
	Reason string
}

ErrPathInvalid is returned if a path is invalid.

func (*ErrPathInvalid) Error

func (e *ErrPathInvalid) Error() string

type ErrUnexpectedType

type ErrUnexpectedType struct {
	Path          string
	Got, Expected string
}

ErrUnexpectedType is returned if a type differs from the expected type.

func (*ErrUnexpectedType) Error

func (e *ErrUnexpectedType) Error() string

type Node

type Node map[string]interface{}

Node contains children that are either nodes, slices, or values of the following types: - bool - string - number - "nil"

Valid child names must not contain periods (PathSeparator).

func (Node) Check

func (n Node) Check() error

Check returns an error when a tree contains any malformed or illegal elements.

Paths returned in errors are not valid paths, as they can contain numbers for slice elements.

func (Node) Compare

func (n Node) Compare(new Node) (modified, added, removed []string)

Compare compares the current tree with the one in new and returns a list of paths for elements that were modified, added or removed.

A change of the content/sub-content of a slice is returned as change of the slice itself.

func (Node) Copy

func (n Node) Copy() Node

Copy returns a copy of itself.

func (Node) CreatePath

func (n Node) CreatePath(path string) (Node, error)

CreatePath makes sure that a given path exists by creating nodes and overwriting existing values.

The function will return the node the path points to.

func (Node) Get

func (n Node) Get(path string, obj interface{}) error

Get reads the element at the path, and writes it into the given object obj.

func (Node) GetBool

func (n Node) GetBool(path string, fallback bool) (result bool)

GetBool returns the bool at the given path. In case of an error, the fallback is returned.

func (Node) GetFloat64

func (n Node) GetFloat64(path string, fallback float64) (result float64)

GetFloat64 returns the float at the given path. In case of an error, the fallback is returned.

func (Node) GetInt64

func (n Node) GetInt64(path string, fallback int64) (result int64)

GetInt64 returns the integer at the given path. In case of an error, the fallback is returned.

func (Node) GetString

func (n Node) GetString(path string, fallback string) (result string)

GetString returns the string at the given path. In case of an error, the fallback is returned.

func (Node) Merge

func (n Node) Merge(new Node)

Merge merges this tree with the new one.

The following rules apply: - If both elements are nodes, their children are merged - Otherwise, the element of the new tree is written - If there is some element in the old, but not in the new tree, the old one is kept - If there is some element in the new, but not in the old tree, the new one is written

Slices will not be merged, but new ones will overwrite old ones.

func (Node) Remove

func (n Node) Remove(path string) error

Remove removes the element and its children at the given path from the tree.

func (Node) Set

func (n Node) Set(path string, obj interface{}) error

Set creates all needed nodes and sets the element at the given path.

func (Node) UnmarshalJSON

func (n Node) UnmarshalJSON(b []byte) error

UnmarshalJSON will unmarshal json data into a Node object. It converts anything to valid tree objects.

func (Node) UnmarshalYAML

func (n Node) UnmarshalYAML(unmarshal func(v interface{}) error) error

UnmarshalYAML will unmarshal yaml data into a Node object. It converts anything to valid tree objects.

type Number

type Number string

Number can represent any integer or float type.

func NumberCreate

func NumberCreate(num interface{}) (Number, error)

NumberCreate takes any number type (integers, floats), and returns a number object that represents the exact value.

func (Number) Float64

func (n Number) Float64() (float64, error)

Float64 returns the number interpreted as float64, or an error if the type doesn't match.

func (Number) Int

func (n Number) Int() (int, error)

Int returns the number interpreted as int, or an error if the type doesn't match.

func (Number) Int64

func (n Number) Int64() (int64, error)

Int64 returns the number interpreted as int64, or an error if the type doesn't match.

func (Number) MarshalJSON

func (n Number) MarshalJSON() ([]byte, error)

MarshalJSON writes the raw string of the Number type

func (Number) MarshalYAML

func (n Number) MarshalYAML() (interface{}, error)

MarshalYAML writes the raw string of the Number type

func (Number) String

func (n Number) String() (string, error)

func (Number) Uint

func (n Number) Uint() (uint, error)

Uint returns the number interpreted as uint, or an error if the type doesn't match.

func (Number) Uint64

func (n Number) Uint64() (uint64, error)

Uint64 returns the number interpreted as uint64, or an error if the type doesn't match.

Jump to

Keyboard shortcuts

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