GetByTraversal returns a *FieldInfo for a given integer path. It is analogous to reflect.FieldByIndex, but using the cached traversal rather than re-executing the reflect machinery each time.
(index []int)
| 42 | // analogous to reflect.FieldByIndex, but using the cached traversal |
| 43 | // rather than re-executing the reflect machinery each time. |
| 44 | func (f StructMap) GetByTraversal(index []int) *FieldInfo { |
| 45 | if len(index) == 0 { |
| 46 | return nil |
| 47 | } |
| 48 | |
| 49 | tree := f.Tree |
| 50 | for _, i := range index { |
| 51 | if i >= len(tree.Children) || tree.Children[i] == nil { |
| 52 | return nil |
| 53 | } |
| 54 | tree = tree.Children[i] |
| 55 | } |
| 56 | return tree |
| 57 | } |
| 58 | |
| 59 | // Mapper is a general purpose mapper of names to struct fields. A Mapper |
| 60 | // behaves like most marshallers in the standard library, obeying a field tag |
no outgoing calls