//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 } 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 }
//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 } 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 }