In this case, it is useful to store pointers on a map instead of a structure:
package main
import "fmt"
type User struct {
Id int
Connected bool
}
func main() {
key := 100
users := map[int]*User{key: &User{Id: 314}}
fmt.Printf("%#v\n", users[key])
users[key].Connected = true
fmt.Printf("%#v\n", users[key])
}
Playground
Conclusion:
&main.User{Id:314, Connected:false}
&main.User{Id:314, Connected:true}
source
share