change from 'Get' to 'Extract'; decrease dependence on perigee
diff --git a/openstack/storage/v1/containers/containers.go b/openstack/storage/v1/containers/containers.go
index 79c3d64..2a5efe1 100644
--- a/openstack/storage/v1/containers/containers.go
+++ b/openstack/storage/v1/containers/containers.go
@@ -2,6 +2,7 @@
import (
"encoding/json"
+ "io/ioutil"
"strings"
)
@@ -34,28 +35,39 @@
Metadata map[string]string
}
-// GetInfo is a function that takes a ListResult (of type *perigee.Response)
+// ExtractInfo is a function that takes a ListResult (of type *http.Response)
// and returns the containers' information.
-func GetInfo(lr ListResult) ([]Container, error) {
+func ExtractInfo(lr ListResult) ([]Container, error) {
var ci []Container
- err := json.Unmarshal(lr.JsonResult, &ci)
+ defer lr.Body.Close()
+ body, err := ioutil.ReadAll(lr.Body)
+ if err != nil {
+ return ci, err
+ }
+ err = json.Unmarshal(body, &ci)
return ci, err
}
-// GetNames is a function that takes a ListResult (of type *perigee.Response)
+// ExtractNames is a function that takes a ListResult (of type *http.Response)
// and returns the containers' names.
-func GetNames(lr ListResult) ([]string, error) {
- jr := string(lr.JsonResult)
- cns := strings.Split(jr, "\n")
+func ExtractNames(lr ListResult) ([]string, error) {
+ var cns []string
+ defer lr.Body.Close()
+ body, err := ioutil.ReadAll(lr.Body)
+ if err != nil {
+ return cns, err
+ }
+ jr := string(body)
+ cns = strings.Split(jr, "\n")
cns = cns[:len(cns)-1]
return cns, nil
}
-// GetMetadata is a function that takes a GetResult (of type *perigee.Response)
+// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
// and returns the custom metadata associated with the container.
-func GetMetadata(gr GetResult) map[string]string {
+func ExtractMetadata(gr GetResult) map[string]string {
metadata := make(map[string]string)
- for k, v := range gr.HttpResponse.Header {
+ for k, v := range gr.Header {
if strings.HasPrefix(k, "X-Container-Meta-") {
key := strings.TrimPrefix(k, "X-Container-Meta-")
metadata[key] = v[0]
diff --git a/openstack/storage/v1/containers/requests.go b/openstack/storage/v1/containers/requests.go
index a1a87a1..df7cc30 100644
--- a/openstack/storage/v1/containers/requests.go
+++ b/openstack/storage/v1/containers/requests.go
@@ -4,14 +4,15 @@
"github.com/racker/perigee"
storage "github.com/rackspace/gophercloud/openstack/storage/v1"
"github.com/rackspace/gophercloud/openstack/utils"
+ "net/http"
)
-type ListResult *perigee.Response
-type GetResult *perigee.Response
+type ListResult *http.Response
+type GetResult *http.Response
// List is a function that retrieves all objects in a container. It also returns the details
// for the account. To extract just the container information or names, pass the ListResult
-// response to the GetInfo or GetNames function, respectively.
+// response to the ExtractInfo or ExtractNames function, respectively.
func List(c *storage.Client, opts ListOpts) (ListResult, error) {
contentType := ""
@@ -28,12 +29,11 @@
url := c.GetAccountURL() + query
resp, err := perigee.Request("GET", url, perigee.Options{
- Results: true,
MoreHeaders: h,
OkCodes: []int{200, 204},
Accept: contentType,
})
- return resp, err
+ return &resp.HttpResponse, err
}
// Create is a function that creates a new container.
@@ -107,7 +107,7 @@
}
// Get is a function that retrieves the metadata of a container. To extract just the custom
-// metadata, pass the GetResult response to the GetMetadata function.
+// metadata, pass the GetResult response to the ExtractMetadata function.
func Get(c *storage.Client, opts GetOpts) (GetResult, error) {
h, err := c.GetHeaders()
if err != nil {
@@ -123,5 +123,5 @@
MoreHeaders: h,
OkCodes: []int{204},
})
- return resp, err
+ return &resp.HttpResponse, err
}