title: Multiple Struct switch?
body: <p>Let's say I have an application that receives json data in two different formats.</p>
  
  <pre><code>f1 = `{"pointtype":"type1", "data":{"col1":"val1", "col2":"val2"}}`
  f2 = `{"pointtype":"type2", "data":{"col3":"val3", "col3":"val3"}}`
  </code></pre>
  
  <p>And I have a struct associated to each type:</p>
  
  <pre><code>type F1 struct {
    col1 string
    col2 string
  }
  
  type F2 struct {
    col3 string
    col4 string
  }
  </code></pre>
  
  <p>Assuming that I use the <code>encoding/json</code> library to turn the raw json data into the struct:
      type Point {
        pointtype string
        data json.RawMessage
      }</p>
  
  <p>How can I decode the data into the appropiate struct just by knowing the pointtype?</p>
  
  <p>I was trying something along the lines of :</p>
  
  <pre><code>func getType(pointType string) interface{} {
      switch pointType {
      case "f1":
          var p F1
          return &amp;p
      case "f2":
          var p F2
          return &amp;p
      }
      return nil
  }
  </code></pre>
  
  <p>Which is not working because the returned value is an interface, not the proper struct type.
  How can I make this kind of switch struct selection work?</p>
  
  <p><a href="http://play.golang.org/p/mjNeWlAw6j" rel="nofollow">here is a non working example</a></p>