Documentation ¶
Overview ¶
Package visit is a library to visit Go data structures (using reflection)
Example ¶
type myStruct struct { String string Map map[string]myStruct Ptr *myStruct } obj := &myStruct{ String: "hello", Map: map[string]myStruct{ "world": {String: "!"}, }, } obj.Ptr = obj var strings []string Values(obj, func(value ValueWithParent) (Action, error) { if value.Kind() == reflect.String { strings = append(strings, value.String()) } return Continue, nil }) fmt.Println(strings)
Output: [hello world !]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assign ¶ added in v1.1.0
func Assign(value ValueWithParent, newValue reflect.Value) error
Assign tries to assign `newValue` to the given `value`, and otherwise returns an error.
func TryAssign ¶ added in v1.1.0
func TryAssign(value ValueWithParent, newValue reflect.Value) bool
TryAssign tries to assign `newValue` to the given `value`, and returns a boolean indicating success.
func ValuesUnsafe ¶ added in v1.1.0
ValuesUnsafe visits a structure *without* performing cycle detection
Types ¶
type Func ¶ added in v1.1.0
type Func func(ValueWithParent) (Action, error)
Func is a visitor function
type ValueWithParent ¶ added in v1.1.0
type ValueWithParent struct { reflect.Value Parent *ValueWithParent Index reflect.Value }
ValueWithParent is a reflect.Value with its parent container (if any) and the corresponding index value.
Click to show internal directories.
Click to hide internal directories.