package reflectwalk
import "github.com/mitchellh/reflectwalk"
reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements.
Index ¶
- Variables
- func Walk(data, walker interface{}) (err error)
- type ArrayWalker
- type EnterExitWalker
- type InterfaceWalker
- type Location
- type MapWalker
- type PointerValueWalker
- type PointerWalker
- type PrimitiveWalker
- type SliceWalker
- type StructWalker
Variables ¶
SkipEntry can be returned from walk functions to skip walking the value of this field. This is only valid in the following functions:
- Struct: skips all fields from being walked
- StructField: skips walking the struct value
Functions ¶
func Walk ¶
func Walk(data, walker interface{}) (err error)
Walk takes an arbitrary value and an interface and traverses the value, calling callbacks on the interface if they are supported. The interface should implement one or more of the walker interfaces in this package, such as PrimitiveWalker, StructWalker, etc.
Types ¶
type ArrayWalker ¶
ArrayWalker implementations are able to handle array elements found within complex structures.
type EnterExitWalker ¶
EnterExitWalker implementations are notified before and after they walk deeper into complex structures (into struct fields, into slice elements, etc.)
type InterfaceWalker ¶
InterfaceWalker implementations are able to handle interface values as they are encountered during the walk.
type Location ¶
type Location uint
const ( None Location = iota Map MapKey MapValue Slice SliceElem Array ArrayElem Struct StructField WalkLoc )
func (Location) String ¶
type MapWalker ¶
MapWalker implementations are able to handle individual elements found within a map structure.
type PointerValueWalker ¶
PointerValueWalker implementations are notified with the value of a particular pointer when a pointer is walked. Pointer is called right before PointerEnter.
type PointerWalker ¶
PointerWalker implementations are notified when the value they're walking is a pointer or not. Pointer is called for _every_ value whether it is a pointer or not.
type PrimitiveWalker ¶
PrimitiveWalker implementations are able to handle primitive values within complex structures. Primitive values are numbers, strings, booleans, funcs, chans.
These primitive values are often members of more complex structures (slices, maps, etc.) that are walkable by other interfaces.
type SliceWalker ¶
SliceWalker implementations are able to handle slice elements found within complex structures.
type StructWalker ¶
type StructWalker interface { Struct(reflect.Value) error StructField(reflect.StructField, reflect.Value) error }
StructWalker is an interface that has methods that are called for structs when a Walk is done.
Source Files ¶
location.go location_string.go reflectwalk.go
- Version
- v1.0.2 (latest)
- Published
- May 3, 2021
- Platform
- windows/amd64
- Imports
- 3 packages
- Last checked
- now –
Tools for package owners.