调试需要,要获得某个包中非导出结构体的值,大概是这样:
package third
type entry struct{
Value atomic.Value
}
这个 Value 中储存的是另一个非导出结构体的指针 *third.anotherEntry :
package third
type anotherEntry struct{
Key ExportStruct //某个导出的结构体
}
楼主用强制转换大法,搞到了 Value 的值,但问题是 Value.Load()是个 interface ,不能通过类型断言转换成*third.anotherEntry,尝试用反射:
reflect.ValueOf(Value.Load()).Elem().Field(0).Interface()
但反射也无法获得非导出结构体的 interface ,会直接 panic 。有什么黑科技可以用吗?