diff --git a/base/reflectx/structs.go b/base/reflectx/structs.go index f7c4a486d6..6b46ffe128 100644 --- a/base/reflectx/structs.go +++ b/base/reflectx/structs.go @@ -245,7 +245,7 @@ func FieldByPath(s reflect.Value, fieldPath string) (reflect.Value, error) { } sv = fv } - return sv.Addr(), nil + return sv, nil } // CopyFields copies the named fields from src struct into dest struct. @@ -299,7 +299,7 @@ func SetFieldsFromMap(obj any, vals map[string]any) error { if err != nil { errs = append(errs, err) } - err = SetRobust(fld.Interface(), v) + err = SetRobust(PointerValue(fld).Interface(), v) if err != nil { err = errors.Log(fmt.Errorf("SetFieldsFromMap: was not able to apply value: %v to field: %s", v, k)) errs = append(errs, err) diff --git a/base/reflectx/structs_test.go b/base/reflectx/structs_test.go index 05a479c4d7..5a69b76605 100644 --- a/base/reflectx/structs_test.go +++ b/base/reflectx/structs_test.go @@ -104,10 +104,10 @@ func TestFieldByPath(t *testing.T) { spv := reflect.ValueOf(sp) fv, err := FieldByPath(spv, "Pet.Age") assert.NoError(t, err) - assert.Equal(t, 7, fv.Elem().Interface()) + assert.Equal(t, 7, fv.Interface()) fv, err = FieldByPath(spv, "Pet.Name") assert.NoError(t, err) - assert.Equal(t, "Pet Gopher", fv.Elem().Interface()) + assert.Equal(t, "Pet Gopher", fv.Interface()) fv, err = FieldByPath(spv, "Pet.Ages") assert.Error(t, err) fv, err = FieldByPath(spv, "Pets.Age")