I want to read full response from the server, but I don't know precise size of it.
I would expect this to work:
message, err := ioutil.ReadAll(conn)
But server is not sending EOF, so this statement just hangs.
I know its a JSON response, so I could read data until the last }, but that seems not the best way how it could be done.
What is the best practice to read full response?
update:
after some while I found out that it's possible this way:
var m map[string]interface{}
d := json.NewDecoder(conn)
d.Decode(&m)
for key, value := range m {
fmt.Print(key)
fmt.Print(" : ")
fmt.Print(value)
fmt.Print("
")
switch vv := value.(type) {
case map[string]interface{}:
for k, v := range vv {
fmt.Print(k)
fmt.Print(" : ")
fmt.Print(v)
fmt.Print("
")
}
}
}