title: How to set an interface{} parameter by reference?
body: <p>I have a function that has a parameter with the type <code>interface{}</code>. This parameter represents my template data. So on each page it stores different data types (mostly structs). I want to append some data to this parameter's data, but it's an <code>interface{}</code> type and I can't do it. </p>
  
  <p>This is what I tried:</p>
  
  <pre><code>func LoadTemplate(templateData interface) {
    appendCustomData(&amp;templateData)
    ... //other functionality that is not relevant
  }
  
  func appendCustomData(dst interface{}) {
      // ValueOf to enter reflect-land
      dstPtrValue := reflect.ValueOf(dst)
      // need the type to create a value
      dstPtrType := dstPtrValue.Type()
      // *T -&gt; T, crashes if not a ptr
      dstType := dstPtrType.Elem()
      // the *dst in *dst = zero
      dstValue := reflect.Indirect(dstPtrValue)
      // the zero in *dst = zero
      zeroValue := reflect.Zero(dstType)
      // the = in *dst = 0
  
      v := reflect.ValueOf(dst).Elem().Elem().FieldByName("HeaderCSS")
      if v.IsValid() {
          v = reflect.ValueOf("new header css value")
      }
  
      reflect.ValueOf(dst).Elem().Elem().FieldByName("HeaderCSS").Set(reflect.ValueOf(v))
  
      //dstValue.Set(zeroValue)
      fmt.Println("new dstValue: ", dstValue)
  }
  </code></pre>
  
  <p>I can successfully get the <code>"HeaderCSS"</code> value. But I can't replace it with another value. What am I doing wrong?</p>
  
  <p>My templateData looks like this:</p>
  
  <p>I have a generic struct:</p>
  
  <pre><code>type TemplateData struct {
      FooterJS template.HTML
      HeaderJS template.HTML
      HeaderCSS template.HTML
      //and some more
  }
  </code></pre>
  
  <p>and I have another struct, such as:</p>
  
  <pre><code>type pageStruct struct {
      TemplateData //extends the previous struct
      Form template.HTML
      // and some other maps/string
  }
  </code></pre>
  
  <p>I send this second struct as templateData argument.</p>
  
  <p>Right now I get this error:</p>
  
  <blockquote>
    <p>"reflect.Value.Set using unaddressable value" at the line: reflect.ValueOf(dst).Elem().Elem().FieldByName("HeaderCSS").Set(reflect.ValueOf(v))</p>
  </blockquote>
  
  <p>The code from above is inspired from this answer: <a href="https://stackoverflow.com/a/26824071/1564840">https://stackoverflow.com/a/26824071/1564840</a></p>
  
  <p>I want to be able to append/edit values from this interface. Any idea how can I do it? Thanks.</p>