我的本地主機服務器正在運行,它只是 docker 中的容器進程。我正在嘗試實現 Go CLIENT 來構建用于創建、列出、更新、刪除功能的 REST api。當我嘗試點擊 URL 時,程序成功退出但給我一個空響應。我進一步觀察到,響應類型被“分塊”,內容長度為 -1。我是 Go 的新手,并試圖找出可能的原因是什么,或者任何人都可以為這個問題提供解決方案。這是我的代碼 - { package mainimport ( "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]stringtype Actions_container map[string]stringfunc 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, "\n", p.Stuff.Actions, "\n", p.Stuff.AgentID, "\n", p.Stuff.AllocationState, "\n", p.Stuff.Compute, "\n", p.Stuff.Created, "\n", p.Stuff.Id, "\n", p.Stuff.Links)}}
- 1 回答
- 0 關注
- 358 瀏覽
添加回答
舉報
0/150
提交
取消