Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { Value interface{} Parent interface{} // Either map[string]interface{} or a slice Path *Path // Exact Path to the current element Name string // Name of the current element Index int // If parent is a slice, the index of the current element in the slice, else -1 Found FoundType // True if the path could not be completely explored }
Context information sent to walk function.
type FoundType ¶
type FoundType int
FoundType adds extra information about not found elements whether what's not found is their parent or themselves.
type Path ¶
Path allows for complex untyped data structure exploration. An instance of this structure represents a step in exploration. Items NOT having `PathTypeElement` as a `Type` are expected to have a non-nil `Next`.
func Parse ¶
Parse transform given path string representation into usable Path.
Example paths:
name object.field object.subobject.field object.array[] object.arrayOfObjects[].field
func (*Path) LastParent ¶
LastParent returns the last step in the path that is not a PathTypeElement, excluding the first step in the path, or nil.
func (*Path) Walk ¶
Walk this path and execute the given behavior for each matching element. Elements are final, meaning they are the deepest explorable element using this path. Only `map[string]interface{}` and n-dimensional slices parents are supported. The given "f" function is executed for each final element matched. If the path cannot be completed because the step's name doesn't exist in the currently explored map, the function will be executed as well, with a the `Context`'s `NotFound` field set to `true`.
type PathType ¶
type PathType int
PathType type of the element being explored.
const ( // PathTypeElement the explored element is used as a final element (leaf). PathTypeElement PathType = iota // PathTypeArray the explored element is used as an array and not a final element. // All elements in the array will be explored using the next Path. PathTypeArray // PathTypeObject the explored element is used as an object (`map[string]interface{}`) // and not a final element. PathTypeObject )