package reflectx
import "zgo.at/zdb/internal/sqlx/reflectx"
Index ¶
- func Deref(t reflect.Type) reflect.Type
- func FieldByIndexes(v reflect.Value, indexes []int) reflect.Value
- func FieldByIndexesReadOnly(v reflect.Value, indexes []int) reflect.Value
- type FieldInfo
- type Mapper
- func NewMapper(tagName string, mapFunc func(string) string) *Mapper
- func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value
- func (m *Mapper) FieldMap(v reflect.Value) map[string]reflect.Value
- func (m *Mapper) TraversalsByName(t reflect.Type, names []string) [][]int
- func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error
- func (m *Mapper) TypeMap(t reflect.Type) *StructMap
- type StructMap
Functions ¶
func Deref ¶
Deref is Indirect for reflect.Types
func FieldByIndexes ¶
FieldByIndexes returns a value for the field given by the struct traversal for the given value.
func FieldByIndexesReadOnly ¶
FieldByIndexesReadOnly returns a value for a particular struct traversal, but is not concerned with allocating nil pointers because the value is going to be used for reading and not setting.
Types ¶
type FieldInfo ¶
type FieldInfo struct { Index []int Path string Field reflect.StructField Zero reflect.Value Name string Options map[string]string Embedded bool Children []*FieldInfo Parent *FieldInfo }
A FieldInfo is metadata for a struct field.
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
A Mapper maps struct fields to names.
A Mapper behaves like most marshallers in the standard library, obeying a field tag for name mapping but also providing a basic transform function.
func NewMapper ¶
NewMapper returns a new mapper using the tag as the struct field tag.
The mapFunc is invoked if the tag is empty, taking the field name as its argument. If this returns an empty things the field is ignored.
func (*Mapper) FieldByName ¶
FieldByName returns a field by its mapped name.
Panics if v is not a struct or pointer to a struct.
Returns zero Value if the name is not found. TODO: that's now how it actually behaves!
zdb only.
func (*Mapper) FieldMap ¶
FieldMap returns the mapper's mapping of field names to reflect values. Panics if v's Kind is not Struct, or v is not Indirectable to a struct kind.
zdb only.
func (*Mapper) TraversalsByName ¶
TraversalsByName returns a slice of int slices which represent the struct traversals for each mapped name.
Panics if t is not a struct or Indirectable to a struct.
Returns empty int slice for each name not found.
func (*Mapper) TraversalsByNameFunc ¶
func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error
TraversalsByNameFunc traverses the mapped names and calls fn with the index of each name and the struct traversal represented by that name.
Panics if t is not a struct or Indirectable to a struct.
Returns the first error returned by fn or nil.
func (*Mapper) TypeMap ¶
TypeMap returns a mapping of field strings to int slices representing the traversal down the struct to reach the field.
type StructMap ¶
type StructMap struct { Tree *FieldInfo Index []*FieldInfo Paths map[string]*FieldInfo Names map[string]*FieldInfo }
A StructMap is an index of field metadata for a struct.
Source Files ¶
reflect.go
- Version
- v0.0.0-20250411114835-98f201430043 (latest)
- Published
- Apr 11, 2025
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 3 days ago –
Tools for package owners.