Documentation
¶
Index ¶
- func Walk(v reflect.Value, visitor Visitor, opts ...WalkOption) error
- type DerefPointer
- type MapKey
- type SliceIndex
- type StructField
- type Visitor
- type WalkOption
- type WalkPath
- func (p WalkPath) IsRoot() bool
- func (p WalkPath) Join(others ...WalkPath) (joined WalkPath)
- func (p WalkPath) Stop() error
- func (p WalkPath) String() (result string)
- func (p WalkPath) TryTraverse(other any) (traversed reflect.Value, err error)
- func (p WalkPath) WalkMap(v reflect.Value, visitor WithMapKeyVisitor, opts ...WalkOption) error
- func (p WalkPath) WalkPointer(v reflect.Value, visitor Visitor, opts ...WalkOption) error
- func (p WalkPath) WalkSlice(v reflect.Value, visitor WithSliceIndexVisitor, opts ...WalkOption) error
- func (p WalkPath) WalkStruct(v reflect.Value, visitor WithStructFieldVisitor, opts ...WalkOption) error
- func (p WalkPath) WrapError(err error) error
- type WalkPathStep
- type WithMapKeyVisitor
- type WithSliceIndexVisitor
- type WithStructFieldVisitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Walk ¶
func Walk(v reflect.Value, visitor Visitor, opts ...WalkOption) error
Walk traverses a reflect.Value recursively, calling the visitor for each value encountered.
Types ¶
type DerefPointer ¶
DerefPointer represents a pointer dereference step in a WalkPath, implemented as a transformation function.
func (DerefPointer) IsNil ¶
func (p DerefPointer) IsNil() bool
type MapKey ¶
MapKey represents a map key step in a WalkPath.
func (MapKey) Compare ¶
Compare returns the lexicographic comparison of this key's name with another.
func (MapKey) EmptyContainer ¶
EmptyContainer tells if WalkPath.WalkMap is running in an empty container with VisitEmptyContainers.
type SliceIndex ¶
type SliceIndex int
SliceIndex represents a slice/array index step in a WalkPath. Negative values represent zero elements.
func (SliceIndex) EmptyContainer ¶
func (s SliceIndex) EmptyContainer() bool
EmptyContainer tells if WalkPath.WalkSlice is running in an empty container with VisitEmptyContainers.
type StructField ¶
type StructField struct {
reflect.StructField
// contains filtered or unexported fields
}
StructField represents a struct field step in a WalkPath.
func (StructField) Compare ¶
func (f StructField) Compare(other StructField) int
Compare returns the lexicographic comparison of this field's name with another.
type Visitor ¶
Visitor is provided to Walk as a callback function. Descending further from this path on can be stopped prematurely by returning the error from WalkPath.Stop.
type WalkOption ¶
type WalkOption func(*walkOpts)
WalkOption configures Walk behavior.
func VisitEmbeddedNilStructs ¶
func VisitEmbeddedNilStructs() WalkOption
VisitEmbeddedNilStructs enables visiting fields of nil embedded struct pointers using zero values.
func VisitEmptyContainers ¶
func VisitEmptyContainers() WalkOption
VisitEmptyContainers enables visiting empty slices, arrays, and maps with a synthetic zero-element step.
type WalkPath ¶
type WalkPath []WalkPathStep
WalkPath represents a path through a nested data structure.
func (WalkPath) TryTraverse ¶
TryTraverse attempts to apply this path to another value, returning the traversed value or an error.
func (WalkPath) WalkMap ¶
func (p WalkPath) WalkMap(v reflect.Value, visitor WithMapKeyVisitor, opts ...WalkOption) error
WalkMap walks through map key-value pairs, providing the key to the visitor using MapKey.StepInto.
func (WalkPath) WalkPointer ¶
WalkPointer walks through pointer and interface values, dereferencing them if non-nil, otherwise falling back to the zero value pointed to, see DerefPointer.StepInto.
func (WalkPath) WalkSlice ¶
func (p WalkPath) WalkSlice(v reflect.Value, visitor WithSliceIndexVisitor, opts ...WalkOption) error
WalkSlice walks through array and slice elements using SliceIndex.StepInto.
func (WalkPath) WalkStruct ¶
func (p WalkPath) WalkStruct(v reflect.Value, visitor WithStructFieldVisitor, opts ...WalkOption) error
WalkStruct walks through exported struct fields, providing field metadata to the visitor using StructField.StepInto.
type WalkPathStep ¶
type WalkPathStep interface {
// StepInto applies this step to a value, returning the descended value.
StepInto(other reflect.Value) reflect.Value
}
WalkPathStep represents a single step in a WalkPath and knows how to descend into values.
type WithMapKeyVisitor ¶
type WithMapKeyVisitor = withVisitor[MapKey]
WithMapKeyVisitor is a visitor that receives map key metadata.
type WithSliceIndexVisitor ¶
type WithSliceIndexVisitor = withVisitor[SliceIndex]
WithSliceIndexVisitor is a visitor that receives slice index metadata.
type WithStructFieldVisitor ¶
type WithStructFieldVisitor = withVisitor[StructField]
WithStructFieldVisitor is a visitor that receives struct field metadata.