check error when json.Unmarshal failed

This commit is contained in:
hangaoshuai 2018-03-27 16:14:18 +08:00
parent f8134deb63
commit ca7e263a29
2 changed files with 8 additions and 2 deletions

View File

@ -31,7 +31,10 @@ type Duration struct {
// UnmarshalJSON implements the json.Unmarshaller interface.
func (d *Duration) UnmarshalJSON(b []byte) error {
var str string
json.Unmarshal(b, &str)
err := json.Unmarshal(b, &str)
if err != nil {
return err
}
pd, err := time.ParseDuration(str)
if err != nil {

View File

@ -104,7 +104,10 @@ func (t *MicroTime) UnmarshalJSON(b []byte) error {
}
var str string
json.Unmarshal(b, &str)
err := json.Unmarshal(b, &str)
if err != nil {
return err
}
pt, err := time.Parse(RFC3339Micro, str)
if err != nil {