Documentation ¶
Index ¶
- func FieldByIndex(v reflect.Value, indexes []int) reflect.Value
- func FieldByIndexReadOnly(v reflect.Value, indexes []int) reflect.Value
- func FindTag(obj interface{}, field, tag string) string
- type Field
- type 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) FieldsByName(v reflect.Value, names []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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldByIndex ¶
FieldByIndex 为给定值返回结构遍历所给定字段的值。
func FieldByIndexReadOnly ¶
FieldByIndexReadOnly 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 Field ¶
type Field struct { Index []int Path string Field reflect.StructField Zero reflect.Value Name string Options map[string]string Embedded bool Children []*Field Parent *Field }
==================================== 以下的代码来自 github.com/jmoiron/sqlx ==================================== Field 是结构体字段的元数据。
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper 是名称到结构字段的通用映射器。 映射器的行为类似于标准库中的大多数编组器,它遵循用于名称映射的字段标签,但也提供了基本的转换功能。
func NewMapper ¶
NewMapper returns a new mapper using the tagName as its struct field tag. If tagName is the empty string, it is ignored.
func NewMapperFunc ¶
NewMapperFunc returns a new mapper which optionally obeys a field tag and a struct field name mapper func given by f. Tags will take precedence, but for any other field, the mapped name will be f(field.Name)
func NewMapperTagFunc ¶
NewMapperTagFunc returns a new mapper which contains a mapper for field names AND a mapper for tag values. This is useful for tags like json which can have values like "name,omitempty".
func (*Mapper) FieldsByName ¶
FieldsByName returns a slice of values corresponding to the slice of names for the value. Panics if v's Kind is not Struct or v is not Indirectable to a struct Kind. Returns zero Value for each name not found.
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.
type StructMap ¶
type StructMap struct { Tree *Field //存储嵌入字段的信息,即:当前字段是一个结构体!!! All []*Field //存储当前结构体所有的字段信息!!! Paths map[string]*Field Names map[string]*Field }
StructMap 是一个结构体中所有字段的元数据. 一个 StructMap 对象只描述 一个结构体中所有的字段信息!!!
func (StructMap) GetByTraversal ¶
GetByTraversal returns a *FieldInfo for a given integer path. It is analogous to reflect.FieldByIndex, but using the cached traversal rather than re-executing the reflect machinery each time.