Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var InvalidIndexErr = errors.New("invalid index")
InvalidIndexErr is returned when a given index is out of bounds.
var UnsupportedTypeErr = errors.New("unsupported type")
UnsupportedTypeErr is returned when an unsupported type is encountered.
Functions ¶
func ComposeValue ¶
ComposeValue returns a map containing the structure of `path`, with `val` as value.
The value is always transformed into a slice unless it is already one. For example, the call
ComposeValue(42, "foo.bar")
yields the following result:
map[string]interface{}{
"foo": map[string]interface{}{
"bar": []int{42},
},
}
Types ¶
type Field ¶
type Field struct {
// Name is the field name.
Name string
// Index is the integer representation of the field name in the case it can be converted to an
// integer value.
Index *int
}
Field is the representation of a term in a field path.
Assuming that 'status.dbCredentials' is a path for a value in a nested object, 'status' and 'dbCredentials' are represented as Field values.
Field contains two members: 'Name' and 'Index'. 'Name' is a string like 'status' or 'dbCredentials', and 'Index' is the optional integer representation of the value, if it can be transformed to a valid positive integer.
type Path ¶
type Path []Field
Path represents a field path.
func NewPathWithParts ¶
NewPathWithParts constructs a Path from given parts.
func (Path) AdjustedPath ¶
AdjustedPath adjusts the current path depending on the head element.
In the case the head of a path ('a' in the 'a.b.c' path) exists and is different than '*', returns itself otherwise returns the path tail ('b.c' in the example).
func (Path) BasePath ¶
BasePath returns the receiver's base path.
For example, returns 'a.b' from the 'a.b.c' path.
func (Path) Clean ¶
Clean creates a new Path without '*' or integer values.
For example, returns 'a.b.c' for 'a.b.*.c' or 'a.b.1.c'.