MCPcopy
hub / github.com/jmoiron/sqlx / FieldsByName

Method FieldsByName

reflectx/reflect.go:147–162  ·  view source on GitHub ↗

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.

(v reflect.Value, names []string)

Source from the content-addressed store, hash-verified

145// for the value. Panics if v's Kind is not Struct or v is not Indirectable
146// to a struct Kind. Returns zero Value for each name not found.
147func (m *Mapper) FieldsByName(v reflect.Value, names []string) []reflect.Value {
148 v = reflect.Indirect(v)
149 mustBe(v, reflect.Struct)
150
151 tm := m.TypeMap(v.Type())
152 vals := make([]reflect.Value, 0, len(names))
153 for _, name := range names {
154 fi, ok := tm.Names[name]
155 if !ok {
156 vals = append(vals, *new(reflect.Value))
157 } else {
158 vals = append(vals, FieldByIndexes(v, fi.Index))
159 }
160 }
161 return vals
162}
163
164// TraversalsByName returns a slice of int slices which represent the struct
165// traversals for each mapped name. Panics if t is not a struct or Indirectable

Callers 1

TestMapperMethodsByNameFunction · 0.80

Calls 3

TypeMapMethod · 0.95
mustBeFunction · 0.85
FieldByIndexesFunction · 0.85

Tested by 1

TestMapperMethodsByNameFunction · 0.64