You cannot assign a struct field off map directly in golang
published on 2013/08/29
package main
import “fmt”
var m = map[string]struct{x, y int} {
“foo”: {2, 3},
}
func main() {
m[“foo”].x = 4 // cannot assign to m[“foo”].x
fmt.Println(m)
}
Here’s above snippet at Go Playground
package main
import “fmt”
var m = map[string]*struct{x, y int} {
“foo”: {2, 3},
}
func main() {
m[“foo”].x = 4
fmt.Println(m[“foo”].x)
}
You can check above snippet at Go Playground