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)
| 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. |
| 132 | func (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 |