title: How to cast interface {} to struct
body: <p>I was looking for how to cast the interface to a struct, but I do not how I can not do it.</p>
  
  <p>I will try to explain my problem. </p>
  
  <pre><code>type Result struct {
      Http_code int
      Http_msg  string
      Response  interface{}}
  </code></pre>
  
  <p>This structure is returned by a function that makes an HTTP request to the server, on the other hand, I have different types of structure to wrap the response. </p>
  
  <p>And this is the struct which I want to cast the interface.</p>
  
  <pre><code>type ResHealth struct {
      Type       string
      Get_health struct {
         Healthy bool
   }}    
  </code></pre>
  
  <p>My problem is that when I try to make the assertion, I always get either segment violation or the program doesn't compile.</p>
  
  <p>The workflow is:</p>
  
  <pre><code>package test
  
  type Result struct {
      Http_code int
      Http_msg  string
      Response  interface{}
  }
  
  type ResHealth struct {
      Type       string
      Get_health struct {
          Healthy bool
      }
  }
  func Do() Result {
    var http_response Result
    var health ResHealth
    +++do something+++
    http_response.Response = health
    return http_response
  }
  
  package Test2
  
  aux := post.Do()
  aux.Response.(ResHealth) // here I have either segment violation or the program doesn't compile
  /////
  </code></pre>