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

Method FieldByName

reflectx/reflect.go:132–142  ·  reflectx/reflect.go::Mapper.FieldByName

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.

(v reflect.Value, name string)

Source from the content-addressed store, hash-verified

130// Panics if v's Kind is not Struct or v is not Indirectable to a struct Kind.
131// Returns zero Value if the name is not found.
132func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value {
133 v = reflect.Indirect(v)
134 mustBe(v, reflect.Struct)
135
136 tm := m.TypeMap(v.Type())
137 fi, ok := tm.Names[name]
138 if !ok {
139 return v
140 }
141 return FieldByIndexes(v, fi.Index)
142}
143
144// FieldsByName returns a slice of values corresponding to the slice of names
145// for the value. Panics if v's Kind is not Struct or v is not Indirectable

Callers 12

TestFlatTagsFunction · 0.95
TestNestedStructFunction · 0.95
TestFieldsEmbeddedFunction · 0.95
TestBasicFunction · 0.80
TestBasicEmbeddedFunction · 0.80
TestInlineStructFunction · 0.80
TestPtrFieldsFunction · 0.80
TestNamedPtrFieldsFunction · 0.80
BenchmarkFieldNameL1Function · 0.80
BenchmarkFieldNameL4Function · 0.80

Calls 3

TypeMapMethod · 0.95
mustBeFunction · 0.85
FieldByIndexesFunction · 0.85

Tested by 12

TestFlatTagsFunction · 0.76
TestNestedStructFunction · 0.76
TestFieldsEmbeddedFunction · 0.76
TestBasicFunction · 0.64
TestBasicEmbeddedFunction · 0.64
TestInlineStructFunction · 0.64
TestPtrFieldsFunction · 0.64
TestNamedPtrFieldsFunction · 0.64
BenchmarkFieldNameL1Function · 0.64
BenchmarkFieldNameL4Function · 0.64