Documentation
¶
Index ¶
- func IterateReferencedTypes(start reflect.Type, action ReferencedTypesIterationAction)
- type ReferencedTypesIterationAction
- type TypePath
- func (p TypePath) AddField(fieldName string) TypePath
- func (p TypePath) AddMapKey() TypePath
- func (p TypePath) AddValue() TypePath
- func (p TypePath) Clone() TypePath
- func (p TypePath) Equals(other TypePath) bool
- func (p TypePath) ResolveType(base reflect.Type) reflect.Type
- func (p TypePath) ResolveValues(base reflect.Value) []reflect.Value
- func (p TypePath) String() string
- type TypeSegment
- type TypeSegmentKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IterateReferencedTypes ¶
func IterateReferencedTypes(start reflect.Type, action ReferencedTypesIterationAction)
IterateReferencedTypes recursively iterates over all referenced types from an initial reflect.Type. The ReferencedTypesIterationAction argument is called for each referenced type. This argument can also control whether the iteration goes deeper into a type or not.
Types ¶
type ReferencedTypesIterationAction ¶
ReferencedTypesIterationAction represents an action to be taken on each iteration of IterateReferencedTypes. This function should return true to go deeper into the current type's referenced types, or false to look no deeper at the current type's referenced types.
NOTE: The TypePath argument this function receives is passed by reference. If you intend to save this value for use after this function returns, you MUST call the Clone() method to keep a copy of the TypePath as you currently see it.
type TypePath ¶
type TypePath []TypeSegment
TypePath represents a path of referenced types starting from an origin reflect.Type. Note the origin reflect.Type is not contained in TypePath.
func (TypePath) AddField ¶
AddField adds a named field segment to a TypePath. The modification is done using append, so this action may mutate the input TypePath.
NOTE: There is no guarantee that this constructed TypePath is valid. Use ResolveType to verify that after construction.
func (TypePath) AddMapKey ¶
AddMapKey adds a map key segment to a TypePath. The modification is done using append, so this action may mutate the input TypePath.
NOTE: There is no guarantee that this constructed TypePath is valid. Use ResolveType to verify that after construction.
func (TypePath) AddValue ¶
AddValue adds a map, array, or slice value segment to a TypePath. The modification is done using append, so this action may mutate the input TypePath.
NOTE: There is no guarantee that this constructed TypePath is valid. Use ResolveType to verify that after construction.
func (TypePath) Equals ¶
Equals returns true if and only if the input TypePath has the exact same segments as this TypePath.
func (TypePath) ResolveType ¶
ResolveType follows the TypePath to its end and returns the reflect.Type of the last referenced type. The initial type, base, must be provided, since TypePath is a relative path. If the TypePath represents a chain of type references that is not valid, this will panic.
func (TypePath) ResolveValues ¶
ResolveValues follows the TypePath to its end and returns a slice of all the values at that location. The initial value, base, must have the type of the origin reflect.Type this TypePath was made for. If the TypePath represents a chain of type references that is not valid, this will panic.
This function returns a slice of values because some segments may map to many values. Field segments always map to a single value, but map key and (map, slice, or array) value segments may map to zero or more values, depending on the value of the input argument.
type TypeSegment ¶
type TypeSegment struct { Kind TypeSegmentKind // If Kind is FieldSegmentKind, then FieldName contains the name of the referenced field. FieldName string }
TypeSegment represents a single segment in a TypePath. This segment is a single reference from one reflect.Type to another reflect.Type.
func (TypeSegment) String ¶
func (s TypeSegment) String() string
type TypeSegmentKind ¶
type TypeSegmentKind int
TypeSegmentKind is a enum for the types of TypeSegment
const ( // FieldSegmentKind represents a referenced field type on a Go type FieldSegmentKind TypeSegmentKind = iota // MapKeySegmentKind represents the key type of a Go map MapKeySegmentKind // ValueSegmentKind represents the value type of a Go map, array, or slice ValueSegmentKind )