title: How do I use type switch on struct fields (when field is of interface type)?
body: <p>See: <a href="http://play.golang.org/p/GDCasRwYOp" rel="nofollow">http://play.golang.org/p/GDCasRwYOp</a></p>
  
  <p>I have a need to do things based on the type of the struct fields.</p>
  
  <p>The following does not work when a field is of interface type.</p>
  
  <p>I think I get why this is not working. But is there a way to do what I want to do?</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "reflect"
  )
  
  type TT struct {
      Foo int
  }
  
  type II interface {
      Bar(int) (int, error)
  }
  
  type SS struct {
      F1 TT
      F2 II
  }
  
  func main() {
      var rr SS
      value := reflect.ValueOf(rr)
      for ii := 0; ii &lt; value.NumField(); ii++ {
          fv := value.Field(ii)
          xv := fv.Interface()
          switch vv := xv.(type) {
          default:
              fmt.Printf("??: vv=%T,%v\n", vv, vv)
          case TT:
              fmt.Printf("TT: vv=%T,%v\n", vv, vv)
          case II:
              fmt.Printf("II: vv=%T,%v\n", vv, vv)
          }
      }
  }
  </code></pre>