title: Why do I get a "cannot assign" error when setting value to a struct as a value in a map?
body: <p>New to Go. Encountered this error and have had no luck finding the cause or the rationale for it:</p>
  
  <p>If I create a struct, I can obviously assign and re-assign the values no problem:</p>
  
  <pre><code>type Person struct {
   name string
   age int
  }
  
  func main() {
    x := Person{"Andy Capp", 98}
    x.age = 99
    fmt.Printf("age: %d\n", x.age)
  }
  </code></pre>
  
  <p>but if the struct is one value in a map:</p>
  
  <pre><code>type Person struct {
       name string
       age int
   }
  
  type People map[string]Person
  
  func main() {
    p := make(People)
    p["HM"] = Person{"Hank McNamara", 39}
    p["HM"].age = p["HM"].age + 1
    fmt.Printf("age: %d\n", p["HM"].age)
  }
  </code></pre>
  
  <p>I get <code>cannot assign to p["HM"].age</code>. That's it, no other info. <a href="http://play.golang.org/p/VRlSItd4eP" rel="noreferrer">http://play.golang.org/p/VRlSItd4eP</a></p>
  
  <p>I found a way around this - creating an <code>incrementAge</code> func on Person, which can be called and the result assigned to the map key, eg <code>p["HM"] = p["HM"].incrementAge()</code>.</p>
  
  <p>But, my question is, what is the reason for this "cannot assign" error, and why shouldn't I be allowed to assign the struct value directly?</p>