func DecodeHook()

in backend/helpers/pluginhelper/api/mapstructure.go [66:105]


func DecodeHook(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
	if data == nil {
		return nil, nil
	}
	if t == reflect.TypeOf(json.RawMessage{}) {
		return json.Marshal(data)
	}
	if t != reflect.TypeOf(common.Iso8601Time{}) && t != reflect.TypeOf(time.Time{}) {
		return data, nil
	}

	var tt time.Time
	var err error
	switch f.Kind() {
	case reflect.String:
		tt, err = common.ConvertStringToTime(data.(string))
	case reflect.Float64:
		tt = time.Unix(0, int64(data.(float64))*int64(time.Millisecond))
	case reflect.Int64:
		tt = time.Unix(0, data.(int64)*int64(time.Millisecond))
	case reflect.Struct:
		if f == reflect.TypeOf(time.Time{}) || f == reflect.TypeOf(common.Iso8601Time{}) {
			return data, nil
		}
	case reflect.Ptr:
		if f == reflect.TypeOf(&time.Time{}) || f == reflect.TypeOf(&common.Iso8601Time{}) {
			return data, nil
		}
	}
	if err != nil {
		return data, nil
	}
	switch t {
	case reflect.TypeOf(common.Iso8601Time{}):
		return common.Iso8601Time{Time: tt}, nil
	case reflect.TypeOf(&common.Iso8601Time{}):
		return &common.Iso8601Time{Time: tt}, nil
	}
	return data, nil
}