(f reflect.Type, t reflect.Type, data interface{})
| 32 | ) |
| 33 | |
| 34 | func DecodeHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) { |
| 35 | if data == nil { |
| 36 | return nil, nil |
| 37 | } |
| 38 | if t == reflect.TypeOf(json.RawMessage{}) { |
| 39 | return json.Marshal(data) |
| 40 | } |
| 41 | // to support decoding url.Values (query string) to non-array variables |
| 42 | if t.Kind() != reflect.Slice && t.Kind() != reflect.Array && |
| 43 | (f.Kind() == reflect.Slice || f.Kind() == reflect.Array) { |
| 44 | v := reflect.ValueOf(data) |
| 45 | if v.Len() == 1 { |
| 46 | data = v.Index(0).Interface() |
| 47 | var result interface{} |
| 48 | err := DecodeMapStruct(data, &result, true) |
| 49 | return result, err |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if t != reflect.TypeOf(common.Iso8601Time{}) && t != reflect.TypeOf(time.Time{}) { |
| 54 | return data, nil |
| 55 | } |
| 56 | |
| 57 | var tt time.Time |
| 58 | var err error |
| 59 | |
| 60 | switch f.Kind() { |
| 61 | case reflect.String: |
| 62 | tt, err = common.ConvertStringToTime(data.(string)) |
| 63 | case reflect.Float64: |
| 64 | tt = time.Unix(0, int64(data.(float64))*int64(time.Millisecond)) |
| 65 | case reflect.Int64: |
| 66 | tt = time.Unix(0, data.(int64)*int64(time.Millisecond)) |
| 67 | } |
| 68 | if err != nil { |
| 69 | return data, nil |
| 70 | } |
| 71 | |
| 72 | if t == reflect.TypeOf(common.Iso8601Time{}) { |
| 73 | return common.Iso8601Time{Time: tt}, nil |
| 74 | } |
| 75 | return tt, nil |
| 76 | } |
| 77 | |
| 78 | // DecodeMapStruct with time.Time and Iso8601Time support |
| 79 | func DecodeMapStruct(input interface{}, result interface{}, zeroFields bool) errors.Error { |
nothing calls this directly
no test coverage detected