title: In go (golang), how can you cast an interface pointer into a struct pointer?
body: <p>I want to use some external code that requires a pointer to a struct.  At the point that the code is called, I have an interface variable.  </p>
  
  <p>When creating a pointer off of that variable, the pointer's type is <code>interface{}*</code> when I need it to be the pointer type of the struct's type.</p>
  
  <p>Image the code in <code>TestCanGetStructPointer</code> <strong>does not know about the Cat class</strong>, and that it exists in some external package.</p>
  
  <p>How can I cast it to this?</p>
  
  <p>Here is a code sample:</p>
  
  <pre><code>import (
      "reflect"
      "testing"
  )   
  
  type Cat struct {
      name string
  }
  
  type SomethingGeneric struct {
      getSomething func() interface{}
  }
  
  func getSomeCat() interface{} {
      return Cat{}
  }
  
  var somethingForCats = SomethingGeneric{getSomething: getSomeCat}
  
  func TestCanGetStructPointer(t *testing.T) {
      interfaceVariable := somethingForCats.getSomething()
  
      pointer := &amp;interfaceVariable
  
      interfaceVarType := reflect.TypeOf(interfaceVariable)
      structPointerType := reflect.PtrTo(interfaceVarType)
      pointerType := reflect.TypeOf(pointer)
  
      if pointerType != structPointerType {
          t.Errorf("Pointer type was %v but expected %v", pointerType, structPointerType)
      }
  
  }
  </code></pre>
  
  <p>The test fails with:</p>
  
  <p><code>Pointer type was *interface {} but expected *parameterized.Cat</code></p>