本文整理汇总了Golang中github.com/coreos/fleet/Godeps/_workspace/src/code/google/com/p/google-api-go-client/googleapi.CloseBody函数的典型用法代码示例。如果您正苦于以下问题:Golang CloseBody函数的具体用法?Golang CloseBody怎么用?Golang CloseBody使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CloseBody函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Do
func (c *UnitStateListCall) Do() (*UnitStatePage, error) {
var body io.Reader = nil
params := make(url.Values)
params.Set("alt", "json")
if v, ok := c.opt_["machineID"]; ok {
params.Set("machineID", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["nextPageToken"]; ok {
params.Set("nextPageToken", fmt.Sprintf("%v", v))
}
if v, ok := c.opt_["unitName"]; ok {
params.Set("unitName", fmt.Sprintf("%v", v))
}
urls := googleapi.ResolveRelative(c.s.BasePath, "state")
urls += "?" + params.Encode()
req, _ := http.NewRequest("GET", urls, body)
googleapi.SetOpaque(req.URL)
req.Header.Set("User-Agent", "google-api-go-client/0.5")
res, err := c.s.client.Do(req)
if err != nil {
return nil, err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return nil, err
}
var ret *UnitStatePage
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err
}
return ret, nil
// {
// "description": "Retrieve a page of UnitState objects.",
// "httpMethod": "GET",
// "id": "fleet.UnitState.List",
// "parameters": {
// "machineID": {
// "location": "query",
// "type": "string"
// },
// "nextPageToken": {
// "location": "query",
// "type": "string"
// },
// "unitName": {
// "location": "query",
// "type": "string"
// }
// },
// "path": "state",
// "response": {
// "$ref": "UnitStatePage"
// }
// }
}
示例2: Do
func (c *UnitsSetCall) Do() error {
var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.desiredunitstate)
if err != nil {
return err
}
ctype := "application/json"
params := make(url.Values)
params.Set("alt", "json")
urls := googleapi.ResolveRelative(c.s.BasePath, "units/{name}")
urls += "?" + params.Encode()
req, _ := http.NewRequest("PUT", urls, body)
req.URL.Path = strings.Replace(req.URL.Path, "{name}", url.QueryEscape(c.name), 1)
googleapi.SetOpaque(req.URL)
req.Header.Set("Content-Type", ctype)
req.Header.Set("User-Agent", "google-api-go-client/0.5")
res, err := c.s.client.Do(req)
if err != nil {
return err
}
defer googleapi.CloseBody(res)
if err := googleapi.CheckResponse(res); err != nil {
return err
}
return nil
// {
// "description": "Set the desired state of a Unit.",
// "httpMethod": "PUT",
// "id": "fleet.Unit.Set",
// "parameterOrder": [
// "name"
// ],
// "parameters": {
// "name": {
// "location": "path",
// "required": true,
// "type": "string"
// }
// },
// "path": "units/{name}",
// "request": {
// "$ref": "DesiredUnitState"
// }
// }
}