I have my localhost server running which is nothing but the container process in a docker.I am trying to implement a Go CLIENT to build REST api's for Create, List, Update, Delete functionalities. When I try to hit the URL, the program exits successfully but gives me an empty response. Further I observed, that the response type is "chunked" with the content length as -1. I am new to Go and trying to figure out what could be the possible reasons or could anyone provide a solution to this problem. Here it my code - {
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Payload struct {
Stuff Data
}
type Data struct {
Id string
Links Links_container
Actions Actions_container
AccountID string
AgentID string
AllocationState string
Compute string
Created string
}
type Links_container map[string]string
type Actions_container map[string]string
func main() {
url := "http://localhost:8080/v1/containers"
res, err := http.Get(url)
if err != nil {
fmt.Println(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
}
var p Payload
err = json.Unmarshal(body, &p)
if err != nil {
panic(err)
}
fmt.Println(p.Stuff.AccountID, "
", p.Stuff.Actions, "
",
p.Stuff.AgentID, "
", p.Stuff.AllocationState, "
", p.Stuff.Compute,
"
", p.Stuff.Created, "
", p.Stuff.Id, "
", p.Stuff.Links)
}
}
Output-
map[]
map[]
This is the JSON output from the server -
{
"type": "collection",
"resourceType": "container",
"links": {
"self": "…/v1/containers",
},
"createTypes": { },
"actions": { },
"data": [ 2 items
{
"id": "1i2",
"type": "container",
"links": { … },
"actions": { … },
"accountId": "1a1",
"agentId": null,
"allocationState": "active",
"compute": null,
"created": "2014-11-13T23:47:08Z",
"createdTS": 1415922428119,
"data": { … },
"description": null,
"domain": null,
"firstRunning": "2014-11-13T23:49:16Z",
"firstRunningTS": 1415922556030,
"hostname": null,
"imageId": "1i1",
"imageUuid": "docker:dockerfile/ghost:latest",
"instanceTriggeredStop": "stop",
"kind": "container",
"memoryMb": 256,
"name": "dockercontainer",
"primaryAssociatedIpAddress": null,
"primaryIpAddress": "0.0.0.0.",
"removeTime": null,
"removed": null,
"requestedHostId": "1h1",
"startOnCreate": true,
"state": "running",
"token": "xyz",
"transitioning": "no",
"transitioningMessage": null,
"transitioningProgress": null,
"userdata": null,
"uuid": "29614f31-4322-4af4-9a55-d9c9395f5cb7",
"validHostIds": null,
"zoneId": "1z1",
"environment": { },
"command": null,
"commandArgs": [ ],
"directory": null,
"user": null,
"publishAllPorts": false,
"privileged": false,
"dockerVolumes": null,
"ports": [ ],
},
{ … },
],
"sortLinks": { … },
"pagination": { … },
"sort": null,
"filters": { … },
"createDefaults": { },
}