title: Unmarshaling Into an Interface{} and Then Performing Type Assertion
body: <p>I get a <code>string</code> through a rabbitmq message system. Before sending,</p>
  
  <p>I use <code>json.Marshal</code>, convert the outcome to <code>string</code> and send through 
  rabbitmq.</p>
  
  <p>The structs that I convert and send can be: (changed the names and the size of the structs but it should not matter)</p>
  
  <pre><code>type Somthing1 struct{
     Thing        string    `json:"thing"`
     OtherThing   int64     `json:"other_thing"`
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>type Somthing2 struct{
     Croc        int       `json:"croc"`
     Odile       bool      `json:"odile"`
  }
  </code></pre>
  
  <p>The message goes through perfectly as a <code>string</code> and is printed 
  on the other side (some server)</p>
  
  <p>Up until now everything works.
  Now I'm trying to convert them back into their structs and assert the types. </p>
  
  <p>first attempt is by:</p>
  
  <pre><code>func typeAssert(msg string) {
  
   var input interface{}
  
   json.Unmarshal([]byte(msg), &amp;input)
  
   switch input.(type){
   case Somthing1:
      job := Somthing1{}
      job = input.(Somthing1)
      queueResults(job)
  
    case Somthing2:
      stats := Somthing2{}
      stats = input.(Somthing2)
      queueStatsRes(stats)
   default:
  }
  </code></pre>
  
  <p>This does not work. When Printing the type of <code>input</code> after Unmarshaling
  it I get <code>map[string]interface{}</code> (?!?)</p>
  
  <p>and even stranger than that, the map key is the string I got and the map value is empty.</p>
  
  <p>I did some other attempts like:</p>
  
  <pre><code> func typeAssert(msg string) {
  
    var input interface{}
  
    json.Unmarshal([]byte(msg), &amp;input)
  
    switch v := input.(type){
    case Somthing1:
      v = input.(Somthing1)
      queueResults(v)
  
     case Somthing2:
      v = input.(Somthing2)
      queueStatsRes(v)
    default:
  }
  </code></pre>
  
  <p>and also tried writing the switch like was explained in this answer:
  <a href="http://Golang:%20cannot%20type%20switch%20on%20non-interface%20value" rel="noreferrer">Golang: cannot type switch on non-interface value</a></p>
  
  <pre><code>switch v := interface{}(input).(type)
  </code></pre>
  
  <p>still with no success...</p>
  
  <p>Any ideas?</p>