title: Use different structs as a value in map golang
body: <p>Is there any way to create a map into several structs, and then use It?</p>
  
  <p>I have several different structs that implement the same interface and matching input types for each struct.</p>
  
  <p>I want to read data from the different inputs into the structs - without knowing the input type at the compilation time.</p>
  
  <pre><code>type myInput struct {
      InputType  string
      data       []bytes
  }
  
  // Will get as an input after compeleation
  inputs := []myInput{
      myInput{InputType: "a", data: []bytes{0x01, 0x02, 0x03}},
      myInput{InputType: "b", data: []bytes{0x01, 0x02}},
  }
  
  type StructA struct {
     A uint16
     B uint32
  }
  
  func (a StructA) name () {
      fmt.Printf("name is: %d %d", a.A, a.B)
  }
  
  type StructB struct {
     C uint32
  }
  
  func (b StructB) name () {
      fmt.Printf("name is: %d", b.C)
  }
  
  AorB map[string]&lt;???&gt; {
      "a": StructA,
      "b": StructB,
  }
  </code></pre>
  
  <p>At this point, I don't know what to do. I need to take the correct struct by the input type and initialize the struct using <code>binary.Read</code>.</p>
  
  <pre><code>for _, myInput := range (inputs) {
      // ???? :(
      myStruct := AtoB[myInput.InputType]{}
      reader :=bytes.NewReader(input1)
      err := binary.Read(reader, binary.BigEndian, &amp;myStruct)
      fmt.Printf(myStruct.name())
  }
  </code></pre>
  
  <p>Thanks!</p>