NewStructIterator creates returns a new iterator for a struct. This only works with struct types, not maps. It will only iterate over public members of the struct. Currently struct pointers will result in an error
(s interface{})
| 58 | // over public members of the struct. Currently struct pointers will |
| 59 | // result in an error |
| 60 | func NewStructIterator(s interface{}) (*StructIterator, error) { |
| 61 | t := reflect.TypeOf(s).Kind() |
| 62 | if t != reflect.Struct { |
| 63 | return nil, fmt.Errorf("cannot create iterator from type %T", s) |
| 64 | } |
| 65 | |
| 66 | v := reflect.ValueOf(s) |
| 67 | return &StructIterator{ |
| 68 | idx: -1, |
| 69 | numField: v.NumField(), |
| 70 | val: v, |
| 71 | }, nil |
| 72 | } |
no outgoing calls