title: Dynamic Type Assertion Golang
body: <p>I'm trying to convert an interface dynamically back to it's original struct but I am having issues accessing attributes of the struct after the conversion.</p>
  
  <p>Take this code for example.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "log"
  )
  
  type struct1 struct {
      A string
      B string
  }
  
  type struct2 struct {
      A string
      C string
  }
  
  type struct3 struct {
      A string
      D string
  }
  
  func main() {
      s1 := struct1{}
      s1.A = "A"
      structTest(s1)
  
      s2 := struct2{}
      s2.A = "A"
      structTest(s2)
  
      s3 := struct3{}
      s3.A = "A"
      structTest(s3)
  }
  
  func structTest(val interface{}) {
      var typedVal interface{}
  
      switch v := val.(type) {
      case struct1:
          fmt.Println("val is struct1")
      case struct2:
          fmt.Println("val is struct2")
      case struct3:
          fmt.Println("val is struct3")
      default:
          log.Panic("not sure what val is.")
      }
  
      fmt.Println(typedVal.A)
  }
  </code></pre>
  
  <p>I would like to be able to pass in one of 3 known struct types into my function. Then figure out which struct type was passed in to type assert it. Finally I want to be able to access like attributes. </p>
  
  <p>Basically I want to have some basic inheritance in my structs, but so far it seems that it is not possible to do this in go. I saw some posts mentioning inheritance using an interface, but my structs have no methods so I'm not sure how I would use an interface.</p>
  
  <p>Is something like this possible in go?</p>