当前位置: 首页>>代码示例>>Golang>>正文


Golang googleapi.CloseBody函数代码示例

本文整理汇总了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"
	//   }
	// }

}
开发者ID:ericcapricorn,项目名称:fleet,代码行数:56,代码来源:v1-gen.go

示例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"
	//   }
	// }

}
开发者ID:Jitendrakry,项目名称:fleet,代码行数:46,代码来源:v1-alpha-gen.go


注:本文中的github.com/coreos/fleet/Godeps/_workspace/src/code/google/com/p/google-api-go-client/googleapi.CloseBody函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。