TraversalsByNameFunc traverses the mapped names and calls fn with the index of each name and the struct traversal represented by that name. Panics if t is not a struct or Indirectable to a struct. Returns the first error returned by fn or nil.
(t reflect.Type, names []string, fn func(int, []int) error)
| 182 | // each name and the struct traversal represented by that name. Panics if t is not |
| 183 | // a struct or Indirectable to a struct. Returns the first error returned by fn or nil. |
| 184 | func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error { |
| 185 | t = Deref(t) |
| 186 | mustBe(t, reflect.Struct) |
| 187 | tm := m.TypeMap(t) |
| 188 | for i, name := range names { |
| 189 | fi, ok := tm.Names[name] |
| 190 | if !ok { |
| 191 | if err := fn(i, nil); err != nil { |
| 192 | return err |
| 193 | } |
| 194 | } else { |
| 195 | if err := fn(i, fi.Index); err != nil { |
| 196 | return err |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | // FieldByIndexes returns a value for the field given by the struct traversal |
| 204 | // for the given value. |