title: Obtaining reflect.Ptr type to field in a Go struct
body: <p>I am trying to pass to a third-party package a variadic list of pointers to fields in a struct. The package accepts a variadic <code>interface{}</code> list (  <code>func Persist(...interface) error</code>  ), where each of the interface values is a pointer to a variable. I created a function that mocks how the third-party library and prints out the Type and Kind of the pointers (called mockFunction below).</p>
  
  <p>When I pass it the address of the struct variables in a non-variadic way, they have their primitive Types and Values within the mocked function using the reflect calls. However, when I pass them in a variadic way using expansion, they have <code>Type: Type: reflect.Value</code> and <code>Kind: struct</code>. The third-party package does not know how to handle them in this form.</p>
  
  <p>I would like to figure out a way to call the third-party package with a slice of interface{} (e.g. <code>inv := make([]interface{}, 3)</code> and use variadic expansion on the call <code>Persist(inv...)</code> if at all possible.</p>
  
  <p>Here is the code with a link to Go Playground below:</p>
  
  <pre><code>package main
  
  import (
    "fmt"
    "reflect"
  )
  
  type Investment struct {
    Price  float64
    Symbol string
    Rating int64
  }
  
  func main() {
    inv := Investment{Price: 534.432, Symbol: "GBG", Rating: 4}
    s := reflect.ValueOf(&amp;inv).Elem()
    variableParms := make([]interface{}, s.NumField())
    for i := 0; i &lt; s.NumField(); i++ {
      variableParms[i] = s.Field(i).Addr()
    }
  
    // non-variadic call
    mockFunction(&amp;inv.Price, &amp;inv.Symbol, &amp;inv.Rating)
    //variadic call
    mockFunction(variableParms...)
  }
  
  func mockFunction(values ...interface{}) {
    for i, value := range values {
      rv := reflect.ValueOf(value)
      fmt.Printf("value %d has Type: %s and Kind %s\n", i, rv.Type(), rv.Kind())
    }
  }
  </code></pre>
  
  <p><a href="http://play.golang.org/p/Of5rvChWbW" rel="nofollow">Go Playground Link</a></p>
  
  <p>When I run it with the non-variadic parameters, the call to mockFunction returns the native Types and Kinds and the third-party package processes them fine:</p>
  
  <pre><code>value 0 has Type: *float64 and Kind ptr
  value 1 has Type: *string and Kind ptr
  value 2 has Type: *int64 and Kind ptr
  </code></pre>
  
  <p>When I run it with the variadic parameters, the values are different and the third-party package does not know how to handle these types:</p>
  
  <pre><code>value 0 has Type: reflect.Value and Kind struct
  value 1 has Type: reflect.Value and Kind struct
  value 2 has Type: reflect.Value and Kind struct
  </code></pre>
  
  <p>Is there any way to structure the slice definition and the call to what is placed in to the slice so that it can be variadic expanded and look like passing the pointers to the struct fields in the non-variadic way?</p>