Documentation
¶
Index ¶
- Variables
- func ApplyIfString[T any](value any, fn func(string) T, defaultValue ...T) T
- func CollectMethods(target reflect.Value) map[string]reflect.Value
- func ConvertValue(sourceValue reflect.Value, targetType reflect.Type) (reflect.Value, error)
- func FindMethod(target reflect.Value, name string) reflect.Value
- func Indirect(t reflect.Type) reflect.Type
- func IsPointerToStruct(t reflect.Type) bool
- func IsSimilarType(t1, t2 reflect.Type) bool
- func IsTypeCompatible(sourceType, targetType reflect.Type) bool
- func Visit(target reflect.Value, visitor Visitor, opts ...VisitorOption)
- func VisitFor[T any](visitor TypeVisitor, opts ...VisitorOption)
- func VisitOf(value any, visitor Visitor, opts ...VisitorOption)
- func VisitType(targetType reflect.Type, visitor TypeVisitor, opts ...VisitorOption)
- type FieldTypeVisitor
- type FieldVisitor
- type MethodTypeVisitor
- type MethodVisitor
- type StructTypeVisitor
- type StructVisitor
- type TagConfig
- type TraversalMode
- type TypeVisitor
- type VisitAction
- type Visitor
- type VisitorConfig
- type VisitorOption
Constants ¶
This section is empty.
Variables ¶
var ErrCannotConvertType = errors.New("cannot convert source type to target type")
ErrCannotConvertType indicates source type cannot be converted to target type.
Functions ¶
func ApplyIfString ¶
ApplyIfString applies a function to a string value, returning defaultValue for non-strings.
func CollectMethods ¶ added in v0.18.0
CollectMethods collects all methods from a target value as a name-to-value map.
func ConvertValue ¶
ConvertValue converts a source value to the target type.
func FindMethod ¶
FindMethod finds a method on a target value (includes pointer receiver and promoted methods).
func IsPointerToStruct ¶ added in v0.18.0
IsPointerToStruct checks if the given type is a pointer to a struct.
func IsSimilarType ¶
IsSimilarType checks if two types are similar (identical or same generic base type).
func IsTypeCompatible ¶
IsTypeCompatible checks if sourceType is compatible with targetType.
func Visit ¶
func Visit(target reflect.Value, visitor Visitor, opts ...VisitorOption)
Visit traverses a struct using visitor callbacks.
func VisitFor ¶
func VisitFor[T any](visitor TypeVisitor, opts ...VisitorOption)
VisitFor visits a struct type T using type visitor callbacks.
func VisitOf ¶
func VisitOf(value any, visitor Visitor, opts ...VisitorOption)
VisitOf visits a struct value using visitor callbacks.
func VisitType ¶
func VisitType(targetType reflect.Type, visitor TypeVisitor, opts ...VisitorOption)
VisitType traverses a struct type using type visitor callbacks.
Types ¶
type FieldTypeVisitor ¶
type FieldTypeVisitor func(field reflect.StructField, depth int) VisitAction
type FieldVisitor ¶
type FieldVisitor func(field reflect.StructField, fieldValue reflect.Value, depth int) VisitAction
type MethodTypeVisitor ¶
type MethodVisitor ¶
type StructTypeVisitor ¶
type StructTypeVisitor func(structType reflect.Type, depth int) VisitAction
type StructVisitor ¶
type TraversalMode ¶
type TraversalMode int
TraversalMode defines the traversal strategy for visiting struct fields and methods.
const ( DepthFirst TraversalMode = iota BreadthFirst )
type TypeVisitor ¶
type TypeVisitor struct {
VisitStructType StructTypeVisitor
VisitFieldType FieldTypeVisitor
VisitMethodType MethodTypeVisitor
}
TypeVisitor defines callback functions for type-only traversal.
type VisitAction ¶
type VisitAction int
VisitAction represents the action to take after visiting a node.
const ( Continue VisitAction = iota Stop SkipChildren )
type Visitor ¶
type Visitor struct {
VisitStruct StructVisitor
VisitField FieldVisitor
VisitMethod MethodVisitor
}
Visitor defines callback functions for struct traversal.
type VisitorConfig ¶
type VisitorConfig struct {
TraversalMode TraversalMode
Recursive bool
DiveTag TagConfig
MaxDepth int
}
VisitorConfig configures how the traversal should be performed.
type VisitorOption ¶
type VisitorOption func(*VisitorConfig)
VisitorOption configures visitor behavior.
func WithDisableRecursive ¶
func WithDisableRecursive() VisitorOption
func WithDiveTag ¶
func WithDiveTag(tagName, tagValue string) VisitorOption
func WithMaxDepth ¶
func WithMaxDepth(maxDepth int) VisitorOption
func WithTraversalMode ¶
func WithTraversalMode(mode TraversalMode) VisitorOption