title: Go Pointers - append values to slice via pointer
body: <p>I have a struct ProductData and its instance p which has a slice attribute :</p>
  
  <pre><code>type ProductInfo struct {
      TopAttributes []map[string]interface{}
  }
  </code></pre>
  
  <p>I want to set TopAttributes as follows</p>
  
  <pre><code>func (p *ProductInfo) setAttributeData() {
      key := "key"
      value := "value"
      setAttribute(p.TopAttributes, key, value)
  }
  
  func setAttribute(p []map[string]interface{}, key string, value interface{}) {
      val := map[string]interface{}{
          key: value,
      }
      p = append(p, val)
  }
  </code></pre>
  
  <h2>But this does not seem to work.</h2>
  
  <p>However, there is another way which works fine when I define a method as:</p>
  
  <pre><code>   func (p *ProductInfo) setAttributeData() {
      key := "key"
      value := "value"
      p.setAttribute(key, value)
  }
  
  func (p *ProductInfo) setAttribute(key string, value interface{}) {
      val := map[string]interface{}{
          key: value,
      }
      p.TopAttributes = append(p.TopAttributes, val)
  }
  </code></pre>
  
  <p>I want to find out why it is not working. There were no errors in my code, but the data coming was empty.
  I am trying to do this to make it a generic function as I have another BottomAttributes which has to be set the same way. </p>