github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/reflect2/test/struct_eface_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 "github.com/v2pro/plz/reflect2" 6 ) 7 8 func Test_struct_eface(t *testing.T) { 9 type TestObject struct { 10 Field1 interface{} 11 } 12 var pEFace = func(val interface{}) interface{} { 13 return &val 14 } 15 t.Run("SetIndex", testOp(func(api reflect2.API) interface{} { 16 valType := api.TypeOf(TestObject{}).(reflect2.StructType) 17 field1 := valType.FieldByName("Field1") 18 obj := TestObject{} 19 field1.Set(&obj, pEFace(100)) 20 return obj 21 })) 22 t.Run("GetIndex", testOp(func(api reflect2.API) interface{} { 23 obj := TestObject{Field1: 100} 24 valType := api.TypeOf(obj).(reflect2.StructType) 25 field1 := valType.FieldByName("Field1") 26 return field1.Get(&obj) 27 })) 28 }