尝试取消引用作为指向后端的struct对象的指针的接口,以便可以将值传递给函数

I have an interface that represents a pointer to a struct object after it has been initialized. I want to get access to the Value of the object that the interface references rather than the pointer so that I can pass it by value to a function as the interface type.

Here is an example of my issue: https://play.golang.org/p/_3vKThlj-V

I want to be able to pass val by value to the function EvalTest in my main function so that I can overwrite the pointer to the TestStruct object in another thread without causing pointer dereference issues in another thread.

The problem is that I'm running several thousand go routines against my interface object, but every 50 go routine calls I have to re-initialize my pointer due to a constraint of the system I'm integrating with. This seems to be leading to an inconsistent state where the new struct initialization is not completely finished when the go routines attempt to access it again. So the reason I wanted to pass it by value was so that I don't have to worry about the pointer being swapped out.

Any thoughts on this?

This was solved by utilizing a channel for my integration api connection and passing a new pointer down the channel whenever it was successfully initialized. There were also some other optimizations that I was able to use to ensure that I was only replacing the pointer in the event of a successful connection. Here is an example of what I used that I got from Paul K in the Go slack channel.

https://play.golang.org/p/AmbsfQOzol