I am trying to convert HTTP JSON body response to map[string]interface{} in golang/go.
This is the code I wrote:
func fromHTTPResponse(httpResponse *http.Response, errMsg string )(APIResponse, error){
temp, _ := strconv.Atoi(httpResponse.Status)
var data map[string]interface{}
resp, errResp := json.Marshal(httpResponse.Body)
defer httpResponse.Body.Close()
if errResp != nil {
return APIResponse{}, errResp
}
err := json.Unmarshal(resp, &data)
if err != nil {
return APIResponse{}, err
}
return APIResponse{httpResponse.Status, data, (temp == OK_RESPONE_CODE), errMsg, map[string]interface{}{} }, nil
}
I successfully connect to the server. The response's body contains JSON data. After running the code, data points to nil, why is that?