I was looking for how to cast the interface to a struct, but I do not how I can not do it.
I will try to explain my problem.
type Result struct {
Http_code int
Http_msg string
Response interface{}}
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.
And this is the struct which I want to cast the interface.
type ResHealth struct {
Type string
Get_health struct {
Healthy bool
}}
My problem is that when I try to make the assertion, I always get either segment violation or the program doesn't compile.
The workflow is:
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
/////