fix issue in gconv.Struct* functions panic when converting attribute value is nil

This commit is contained in:
John 2020-02-05 22:06:24 +08:00
parent b15075fdfe
commit 1999ef95c1

View File

@ -9,6 +9,7 @@ package gconv
import (
"errors"
"fmt"
"github.com/gogf/gf/internal/empty"
"reflect"
"regexp"
"strings"
@ -223,7 +224,7 @@ func bindVarToStructAttr(elem reflect.Value, name string, value interface{}) (er
err = bindVarToReflectValue(structFieldValue, value)
}
}()
if value == nil {
if empty.IsNil(value) {
structFieldValue.Set(reflect.Zero(structFieldValue.Type()))
} else {
structFieldValue.Set(reflect.ValueOf(Convert(value, structFieldValue.Type().String())))
@ -246,7 +247,7 @@ func bindVarToStructByIndex(elem reflect.Value, index int, value interface{}) (e
err = bindVarToReflectValue(structFieldValue, value)
}
}()
if value == nil {
if empty.IsNil(value) {
structFieldValue.Set(reflect.Zero(structFieldValue.Type()))
} else {
structFieldValue.Set(reflect.ValueOf(Convert(value, structFieldValue.Type().String())))