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


Golang Session.Get方法代码示例

本文整理汇总了Golang中github.com/christoffetzer/golang-client/openstack.Session.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Get方法的具体用法?Golang Session.Get怎么用?Golang Session.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/christoffetzer/golang-client/openstack.Session的用法示例。


在下文中一共展示了Session.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ListObjects

//ListObjects calls the OpenStack list object API using previously
//obtained token. "Limit", "marker", "prefix", "path", "delim" corresponds
//to the API's "limit", "marker", "prefix", "path", and "delimiter".
func ListObjects(session *openstack.Session, limit int64,
	marker, prefix, path, delim, conURL string) ([]byte, error) {
	var query url.Values = url.Values{}
	query.Add("format", "json")
	if limit > 0 {
		query.Add("limit", strconv.FormatInt(limit, 10))
	}
	if marker != "" {
		query.Add("marker", url.QueryEscape(marker))
	}
	if prefix != "" {
		query.Add("prefix", url.QueryEscape(prefix))
	}
	if path != "" {
		query.Add("path", url.QueryEscape(path))
	}
	if delim != "" {
		query.Add("delimiter", url.QueryEscape(delim))
	}
	resp, err := session.Get(conURL, &query, nil)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close() // CF
	if err = util.CheckHTTPResponseStatusCode(resp); err != nil {
		return nil, err
	}
	body, err := ioutil.ReadAll(resp.Body)
	// defer resp.Body.Close()
	if err != nil {
		return []byte{}, err
	}
	return body, nil
}
开发者ID:christoffetzer,项目名称:golang-client,代码行数:37,代码来源:objectstorage.go

示例2: GetObject

//GetObject calls the OpenStack retrieve object API using previously
//obtained token. It returns http.Header, object / file content downloaded
//from the server, and err.
//
//Since this implementation of GetObject retrieves header info, it
//effectively executes GetObjectMeta also in addition to getting the
//object content.
func GetObject(session *openstack.Session, url string) (http.Header, []byte, error) {
	resp, err := session.Get(url, nil, nil)
	if err != nil {
		return nil, nil, err
	}
	defer resp.Body.Close() // CF
	if err = util.CheckHTTPResponseStatusCode(resp); err != nil {
		return nil, nil, err
	}
	var body []byte
	if body, err = ioutil.ReadAll(resp.Body); err != nil {
		return nil, nil, err
	}
	// resp.Body.Close()
	return resp.Header, body, nil
}
开发者ID:christoffetzer,项目名称:golang-client,代码行数:23,代码来源:objectstorage.go


注:本文中的github.com/christoffetzer/golang-client/openstack.Session.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。