| 42 | } |
| 43 | |
| 44 | func newStructSpec(t reflect.Type, fieldTag string) *structSpec { |
| 45 | numField := t.NumField() |
| 46 | out := &structSpec{ |
| 47 | m: make(map[string]*structField, numField), |
| 48 | } |
| 49 | |
| 50 | for i := 0; i < numField; i++ { |
| 51 | f := t.Field(i) |
| 52 | |
| 53 | tag := f.Tag.Get(fieldTag) |
| 54 | if tag == "" || tag == "-" { |
| 55 | continue |
| 56 | } |
| 57 | |
| 58 | tag = strings.Split(tag, ",")[0] |
| 59 | if tag == "" { |
| 60 | continue |
| 61 | } |
| 62 | |
| 63 | // Use the built-in decoder. |
| 64 | kind := f.Type.Kind() |
| 65 | if kind == reflect.Pointer { |
| 66 | kind = f.Type.Elem().Kind() |
| 67 | } |
| 68 | out.set(tag, &structField{index: i, fn: decoders[kind]}) |
| 69 | } |
| 70 | |
| 71 | return out |
| 72 | } |
| 73 | |
| 74 | //------------------------------------------------------------------------------ |
| 75 | |