I have to make two HTTP API calls in GoLang, the first API call returns this json response:
{
"status": 200,
"msg": "OK",
"result": {
"id": "24",
"folderid": "4248"
}
}
My json struct for first response is setup like this:
type One struct {
Status int `json:"status"`
Msg string `json:"msg"`
Result struct {
ID string `json:"id"`
Folderid string `json:"folderid"`
} `json:"result"`
}
The second call is where the problem is. As you can see the first API call returns a result -> id. This ID should be the name for the beginning of my second struct, but I can't seem how to make it dynamic or put a result as my structure name. This ID (24) will always change based on the first API call. I have no way currently to parse the second call's JSON and setup my struct. On the second API call I want to access the remoteurl/status.
Second call result (I can not parse):
{
"status": 200,
"msg": "OK",
"result": {
24: ** THIS IS DYNAMIC** {
"id": 24,
"remoteurl": "http://proof.ovh.net/files/100Mio.dat",
"status": "new",
"bytes_loaded": null,
"bytes_total": null,
"folderid": "4248",
"added": "2015-02-21 09:20:26",
"last_update": "2015-02-21 09:20:26",
"extid": false,
"url": false
}
}
}
Does anyone know how to setup my struct or go about this. I am a new programmer and go and have worked on this for 4 days. And decided to ask for some help, since I am in school and have normal homework.