in encoder/json.go [157:204]
func fixFieldType(f interface{}, dt string) (interface{}, error) {
var err error
switch v := f.(type) {
case float64:
switch dt {
case "bigint", "enum", "set":
f = int64(v)
case "int", "integer", "tinyint", "smallint", "mediumint", "year":
f = int32(v)
case "float":
f = float32(v)
}
case string:
switch dt {
case "blob", "tinyblob", "mediumblob", "longblob", "binary", "varbinary":
f, err = base64.StdEncoding.DecodeString(v)
if err != nil {
return nil, err
}
case "timestamp", "datetime":
t := ZeroTime
//MySQL binlog reader library return string intread of time.Time for
//"zero" time.
if !strings.HasPrefix(v, "0000-00-00 00:00:00") {
//t.UnmashalJSON can't be used, because it uses RFC3339 to parse while
//MarshalJSON uses RFC3339Nano format.
t, err = time.Parse(time.RFC3339Nano, v)
if err != nil {
return nil, err
}
if dt == "timestamp" && !t.Equal(time.Time{}) {
//If the local time is UTC while marshalling, then timezone info is
//not included in result, in this case when parsing back, timezone is
//not matched to local timezone. We forcibly set zone to Local if
//local zone is UTC and parsed time in UTC.
name, _ := time.Now().Zone() //TODO: cache this
if t.Location().String() == "UTC" && name == "UTC" {
t = t.In(time.Local)
}
} else {
t = t.In(time.UTC)
}
}
f = t
}
}
return f, nil
}