Can't assign to struct variable
go
Solution
For example,
package main
import "fmt"
type User struct {
Id int
Connected bool
}
func main() {
users := make(map[int]User)
id := 42
user := User{id, false}
users[id] = user
fmt.Println(users)
user = users[id]
user.Connected = true
users[id] = user
fmt.Println(users)
}
Output:
map[42:{42 false}]
map[42:{42 true}]
Problem
I've got a map ``` var users = make(map[int]User) ``` I'm filling the map and all is fine. Later, I want to assign to one of the values of User, but I get an error. ``` type User struct { Id int Connected bool } users[id].Connected = true // Error ``` I've also tried to write a function that assigns to it, but that doesn't work either.