Deep walk by object with reflection. With recursive loop protection.
type S struct {
Val1 int
Slice []string
}
v := S{
Val1: 2,
Slice: []string{"hello", "world"},
}
_ = New(func(info WalkInfo) error {
val := info.Value.Interface()
_ = val
if info.IsStructField {
fmt.Println(info.Value.Interface())
}
return nil
}).Walk(v)
// Output:
// 2
// [hello world]