title: How to update map values in Go
body: <p>I want to build a map with string key and struct value with which I'm able to update struct value in the map identified by map key.</p>
  <p>I've tried this (<a href="https://play.golang.org/p/jwB6eL2uaM" rel="noreferrer">playground</a>):</p>
  <pre><code>func main() {
  
      dataReceived := []Data{
          Data{ID: &quot;D1&quot;, Value: &quot;V1&quot;},
          Data{ID: &quot;D2&quot;, Value: &quot;V2&quot;},
          Data{ID: &quot;D3&quot;, Value: &quot;V3&quot;},
          Data{ID: &quot;D4&quot;, Value: &quot;V4&quot;},
          Data{ID: &quot;D5&quot;, Value: &quot;V5&quot;},
      }
  
      dataManaged := map[string]Data{}
  
      for _, v := range dataReceived {
          fmt.Println(&quot;Received ID:&quot;, v.ID, &quot;Value:&quot;, v.Value)
          dataManaged[v.ID] = v
      }
  
      fmt.Println()
  
      for m, n := range dataManaged {
          n.Value = &quot;UpdatedData for &quot; + n.ID
          fmt.Println(&quot;Data key:&quot;, m, &quot;Value:&quot;, n.Value)
      }
  
      fmt.Println()
  
      for o, p := range dataManaged {
          fmt.Println(&quot;Data key:&quot;, o, &quot;Value:&quot;, p.Value)
      }
  
  }
  </code></pre>
  <p>and also <a href="https://play.golang.org/p/h4k6jj2ICw" rel="noreferrer">this</a> which doesn't give me desired output.</p>
  <p>What I really want is this:</p>
  <pre><code>Received ID: D1 Value: V1
  Received ID: D2 Value: V2
  Received ID: D3 Value: V3
  Received ID: D4 Value: V4
  Received ID: D5 Value: V5
  
  Data key: D1 Value: UpdatedData for D1
  Data key: D2 Value: UpdatedData for D2
  Data key: D3 Value: UpdatedData for D3
  Data key: D4 Value: UpdatedData for D4
  Data key: D5 Value: UpdatedData for D5
  
  Data key: D1 Value: UpdatedData for D1
  Data key: D2 Value: UpdatedData for D2
  Data key: D3 Value: UpdatedData for D3
  Data key: D4 Value: UpdatedData for D4
  Data key: D5 Value: UpdatedData for D5</code></pre>