代码拉取完成,页面将自动刷新
package gosql
import (
"reflect"
"github.com/jmoiron/sqlx/reflectx"
)
type ReflectMapper struct {
mapper *reflectx.Mapper
}
func NewReflectMapper(tagName string) *ReflectMapper {
return &ReflectMapper{
mapper: reflectx.NewMapper(tagName),
}
}
// FieldByName returns a field by its mapped name as a reflect.Value.
// Panics if v's Kind is not Struct or v is not Indirectable to a struct Kind.
// Returns zero Value if the name is not found.
func (r *ReflectMapper) FieldByName(v reflect.Value, name string) reflect.Value {
return r.mapper.FieldByName(v, name)
}
// 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.
func (r *ReflectMapper) FieldMap(v reflect.Value) map[string]reflect.Value {
v = reflect.Indirect(v)
ret := map[string]reflect.Value{}
tm := r.mapper.TypeMap(v.Type())
for tagName, fi := range tm.Names {
//fmt.Println(tagName,fi.Parent.Zero.Kind(),fi.Parent.Field.Anonymous)
if (fi.Parent.Zero.Kind() == reflect.Struct || (fi.Zero.Kind() == reflect.Ptr && fi.Zero.Type().Elem().Kind() == reflect.Struct)) && !fi.Parent.Field.Anonymous {
continue
}
ret[tagName] = reflectx.FieldByIndexes(v, fi.Index)
}
return ret
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。