Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSkip - signal for skip iteration over value // can be returned for array, interface, map, map key, slice, struct, ptr, // for other kinds - unspecified behaviour and it may be change for feature versions ErrSkip = errors.New("skip value") // ErrUnknownKind mean reflect walk see unknown kind of type - need to update library ErrUnknownKind = errors.New("unknown kind") )
Functions ¶
This section is empty.
Types ¶
type WalkInfo ¶
type WalkInfo struct {
// Value - reflection Value for inspect/manupulate variable
Value reflect.Value
// Parent is info of prev node in travel tree hierarchy
// Parent == nil for first visited value
Parent *WalkInfo
// DirectPointer hold address of Value data (Value.ptr) 0 if value not addressable
DirectPointer unsafe.Pointer
// IsVisited true if loop protection disabled and walker detect about value was visited already
IsVisited bool
// contains filtered or unexported fields
}
WalkInfo send to walk callback with every value
func (*WalkInfo) HasDirectPointer ¶ added in v0.0.3
HasDirectPointer check if w.DirectPointer has non zero value
func (*WalkInfo) IsMapValue ¶
IsMapValue mean Value direct use as map value
type Walker ¶
type Walker struct {
LoopProtection bool
// contains filtered or unexported fields
}
Walker provide settings and state for Walk function
Example ¶
type S struct {
Val1 int
Slice []string
}
val := S{
Val1: 2,
Slice: []string{"hello", "world"},
}
_ = New(func(info *WalkInfo) error {
fmt.Println(info.Value.Interface())
return nil
}).Walk(val)
Output: {2 [hello world]} 2 [hello world] hello world
func New ¶
New create new walker with f callback f will call for every field, item, etc of walked object f can called multiply times for same address with different item type for example: type T struct { Val int } f will called for struct T and for Pub int
if f return ErrSkip - skip the struct (, map, slice, ... see ErrSkip comment) if f return other non nil error - stop walk and return the error to walk caller
func (*Walker) WithDisableLoopProtection ¶
WithDisableLoopProtection disable loop protection. callback must self-detect loops and return ErrSkip