title: Set the value of a struct field with reflection when the field is a pointer-to-x
body: <p>I have a struct of pointers to various primitives. The struct is a config for an application and the reason the fields are pointers is so I can determine between a field set to the default and a field that hasn't been set at all - to enforce &quot;required&quot; fields.</p>
  <p>Here is a simple example:</p>
  <pre><code>type Config struct {
      A *string
      B *int
      C *bool
      D *[]string // wildcard!
  }
  </code></pre>
  <p>So I grab the <code>reflect.Value</code> via <code>reflect.ValueOf(*cfg)</code> which gives me a <code>.Field</code> on each element, which I iterate through.</p>
  <p>The thing is, each element doesn't pass <code>CanAddr</code> or <code>CanSet</code>, I can't seem to find a way to set the value held behind the pointer. Is this a limitation of the language? Will I need to make my fields non-pointers? That would suck as there would be no way to determine if a user specified an empty string or just didn't set it at all for example.</p>
  <p><em>Oh and bonus points for setting/appending a []string field! That one confused me even <strong>without</strong> pointers thrown in the mix!</em></p>