Documentation ¶
Index ¶
- Constants
- func PathContains(path, subPath string) bool
- func PathJoin(elem ...string) string
- func PathSplit(path string) []string
- type ErrCannotModify
- type ErrElementNotFound
- type ErrKeyIsNotString
- type ErrPathInsideValue
- type ErrPathInvalid
- type ErrUnexpectedType
- type Node
- func (n Node) Check() error
- func (n Node) Compare(new Node) (modified, added, removed []string)
- func (n Node) Copy() Node
- func (n Node) CreatePath(path string) (Node, error)
- func (n Node) Get(path string, obj interface{}) error
- func (n Node) GetBool(path string, fallback bool) (result bool)
- func (n Node) GetFloat64(path string, fallback float64) (result float64)
- func (n Node) GetInt64(path string, fallback int64) (result int64)
- func (n Node) GetString(path string, fallback string) (result string)
- func (n Node) Merge(new Node)
- func (n Node) Remove(path string) error
- func (n Node) Set(path string, obj interface{}) error
- func (n Node) UnmarshalJSON(b []byte) error
- func (n Node) UnmarshalYAML(unmarshal func(v interface{}) error) error
- type Number
- func (n Number) Float64() (float64, error)
- func (n Number) Int() (int, error)
- func (n Number) Int64() (int64, error)
- func (n Number) MarshalJSON() ([]byte, error)
- func (n Number) MarshalYAML() (interface{}, error)
- func (n Number) String() (string, error)
- func (n Number) Uint() (uint, error)
- func (n Number) Uint64() (uint64, error)
Constants ¶
const PathSeparator = "."
PathSeparator delimits single path elements.
Variables ¶
This section is empty.
Functions ¶
func PathContains ¶
PathContains returns whether the path contains the subPath.
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 ¶
ErrPathInvalid is returned if a path is invalid.
func (*ErrPathInvalid) Error ¶
func (e *ErrPathInvalid) Error() string
type ErrUnexpectedType ¶
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 ¶
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 ¶
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) CreatePath ¶
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) GetBool ¶
GetBool returns the bool at the given path. In case of an error, the fallback is returned.
func (Node) GetFloat64 ¶
GetFloat64 returns the float at the given path. In case of an error, the fallback is returned.
func (Node) GetInt64 ¶
GetInt64 returns the integer at the given path. In case of an error, the fallback is returned.
func (Node) GetString ¶
GetString returns the string at the given path. In case of an error, the fallback is returned.
func (Node) Merge ¶
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) UnmarshalJSON ¶
UnmarshalJSON will unmarshal json data into a Node object. It converts anything to valid tree objects.
func (Node) UnmarshalYAML ¶
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 ¶
NumberCreate takes any number type (integers, floats), and returns a number object that represents the exact value.
func (Number) Float64 ¶
Float64 returns the number interpreted as float64, or an error if the type doesn't match.
func (Number) Int ¶
Int returns the number interpreted as int, or an error if the type doesn't match.
func (Number) Int64 ¶
Int64 returns the number interpreted as int64, or an error if the type doesn't match.
func (Number) MarshalJSON ¶
MarshalJSON writes the raw string of the Number type
func (Number) MarshalYAML ¶
MarshalYAML writes the raw string of the Number type