FieldAt gets the field at i
(nth int)
| 135 | |
| 136 | // FieldAt gets the field at i |
| 137 | func (stct *Struct) FieldAt(nth int) (field *Field, err error) { |
| 138 | if stct.node.Fields == nil { |
| 139 | return nil, fmt.Errorf("struct %q in %q has no fields", stct.Name(), stct.file.Path()) |
| 140 | } |
| 141 | i := 0 |
| 142 | for _, field := range stct.node.Fields.List { |
| 143 | for _, name := range field.Names { |
| 144 | if nth == i { |
| 145 | return &Field{ |
| 146 | stct: stct, |
| 147 | name: name.Name, |
| 148 | node: field, |
| 149 | }, nil |
| 150 | } |
| 151 | i++ |
| 152 | } |
| 153 | } |
| 154 | return nil, fmt.Errorf("struct %q in %q has no field at %d", stct.Name(), stct.file.Path(), nth) |
| 155 | } |
| 156 | |
| 157 | func (stct *Struct) Methods() (methods []*Function) { |
| 158 | for _, file := range stct.Package().Files() { |