Struct variable not being updated

后端 未结 1 1011
清歌不尽
清歌不尽 2021-01-26 11:15

I have an array in test code

arr := []Server{}

which asks for arr[0].GetId()

Server is an interface. ServerInstance is a struct impleme

相关标签:
1条回答
  • 2021-01-26 11:35

    You're copying the structs when appending them, rather than placing pointers to the structs themselves in the example. http://play.golang.org/p/rQz9RLTzMU -- works as intended yes? Further info: Golang is a pass-by-value language, so if you're using goroutines and you want to keep the sanctity of your data, you'd be better off using pointers.

    0 讨论(0)
提交回复
热议问题