getValueFromFields doesn't panic on nil pointers
* `IsValid()` won't return `false` for nil pointers unless Value is wrapped in a `reflect.Indirect`.
This commit is contained in:
parent
409121d9e3
commit
4900f219fd
2
utils.go
2
utils.go
@ -267,7 +267,7 @@ func getValueFromFields(value reflect.Value, fieldNames []string) (results []int
|
||||
// as FieldByName could panic
|
||||
if indirectValue := reflect.Indirect(value); indirectValue.IsValid() {
|
||||
for _, fieldName := range fieldNames {
|
||||
if fieldValue := indirectValue.FieldByName(fieldName); fieldValue.IsValid() {
|
||||
if fieldValue := reflect.Indirect(indirectValue.FieldByName(fieldName)); fieldValue.IsValid() {
|
||||
result := fieldValue.Interface()
|
||||
if r, ok := result.(driver.Valuer); ok {
|
||||
result, _ = r.Value()
|
||||
|
Loading…
x
Reference in New Issue
Block a user