mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
fix issue in gconv.Struct* functions panic when converting attribute value is nil
This commit is contained in:
parent
b15075fdfe
commit
1999ef95c1
@ -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())))
|
||||
|
Loading…
Reference in New Issue
Block a user