title: Set struct field which is a pointer using reflection
body: <p>My question is like <a href="https://stackoverflow.com/questions/24890732/set-a-pointer-to-a-field-using-reflection">this one</a> but with a slight difference that my value is an <code>interface{}</code>.</p>
  
  <p>Let assume we have a struct like this:</p>
  
  <pre class="lang-golang prettyprint-override"><code>type User struct {
      ID         int
      Email      string
      ResourceID *int
  }
  </code></pre>
  
  <p>and a function that sets values of input struct.</p>
  
  <pre class="lang-golang prettyprint-override"><code>func setFieldValue(s interface{}, fieldName string, value interface{}) {
      v := reflect.ValueOf(s).Elem()
      fieldVal := v.FieldByName(fieldName)
  
      if fieldVal.Kind() == reflect.Ptr {
          // Here is the problem
          fieldVal.Set(reflect.ValueOf(&amp;value))
      } else {
          fieldVal.Set(reflect.ValueOf(value))
      }
  }
  </code></pre>
  
  <p>It is obvious that if I run the code I get the following error:</p>
  
  <pre><code>panic: reflect.Set: value of type *interface {} is not assignable to type *int
  </code></pre>
  
  <p>here is the code in playground: <a href="https://play.golang.org/p/VUoyRras8SD" rel="nofollow noreferrer">https://play.golang.org/p/VUoyRras8SD</a></p>
  
  <p>What should I do to fix this?</p>