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