I wrote a sample application about assign value to variable. Look at the following code snippet:
package main
import (
"fmt"
)
func main() {
cp := 344
fmt.Println(cp)
cp = 566565
fmt.Println(cp)
res := []struct {
Email string `json:"n.email"`
Activated bool `json:"n.activated"`
}{}
fmt.Println(res)
res = []struct {
Email string `json:"n.email"`
}{}
fmt.Println(res)
}
First cp variable, I assign value then after do it again and it works. At the end cp carry the value 566565. For me is int mutable.
The second code does not work, reassign new struct to res, I got compiler error.
./double_assignment.go:23: cannot use []struct { Email string } literal (type []struct { Email string }) as type []struct { Email string; Activated bool } in assignment
Is struct immutable?