Check valid pointer before use it as Valuer

This commit is contained in:
Jinzhu 2020-08-20 18:13:29 +08:00
parent 06de6e8834
commit f88e8b072c
1 changed files with 5 additions and 5 deletions

View File

@ -473,16 +473,16 @@ func (field *Field) setupValuerAndSetter() {
}
}
if valuer, ok := v.(driver.Valuer); ok {
if v, err = valuer.Value(); err == nil {
err = setter(value, v)
}
} else if reflectV.Kind() == reflect.Ptr {
if reflectV.Kind() == reflect.Ptr {
if reflectV.IsNil() {
field.ReflectValueOf(value).Set(reflect.New(field.FieldType).Elem())
} else {
err = setter(value, reflectV.Elem().Interface())
}
} else if valuer, ok := v.(driver.Valuer); ok {
if v, err = valuer.Value(); err == nil {
err = setter(value, v)
}
} else {
return fmt.Errorf("failed to set value %+v to field %v", v, field.Name)
}