change from 'Get' to 'Extract'; decrease dependence on perigee
diff --git a/acceptance/openstack/storage_test.go b/acceptance/openstack/storage_test.go
index 5934764..d194936 100644
--- a/acceptance/openstack/storage_test.go
+++ b/acceptance/openstack/storage_test.go
@@ -59,7 +59,7 @@
t.Error(err)
return
}
- am := accounts.GetMetadata(gr)
+ am := accounts.ExtractMetadata(gr)
for k := range metadata {
if am[k] != metadata[strings.Title(k)] {
t.Errorf("Expected custom metadata with key: %s", k)
@@ -117,7 +117,7 @@
t.Error(err)
return
}
- cns, err := containers.GetNames(lr)
+ cns, err := containers.ExtractNames(lr)
if err != nil {
t.Error(err)
return
@@ -134,7 +134,7 @@
t.Error(err)
return
}
- cis, err := containers.GetInfo(lr)
+ cis, err := containers.ExtractInfo(lr)
if err != nil {
t.Error(err)
return
@@ -172,7 +172,7 @@
t.Error(err)
return
}
- cm := containers.GetMetadata(gr)
+ cm := containers.ExtractMetadata(gr)
for k := range metadata {
if cm[k] != metadata[strings.Title(k)] {
t.Errorf("Expected custom metadata with key: %s", k)
@@ -251,7 +251,11 @@
t.Error(err)
return
}
- ons := objects.GetNames(lr)
+ ons, err := objects.ExtractNames(lr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
if len(ons) != len(oNames) {
t.Errorf("Expected %d names and got %d", len(oNames), len(ons))
return
@@ -265,7 +269,7 @@
t.Error(err)
return
}
- ois, err := objects.GetInfo(lr)
+ ois, err := objects.ExtractInfo(lr)
if err != nil {
t.Error(err)
return
@@ -294,8 +298,10 @@
t.Error(err)
return
}
- o2Content := objects.GetContent(dr)
-
+ o2Content, err := objects.ExtractContent(dr)
+ if err != nil {
+ t.Error(err)
+ }
dr, err = objects.Download(client, objects.DownloadOpts{
Container: cName,
Name: oNames[0],
@@ -304,8 +310,11 @@
t.Error(err)
return
}
- o1Content := objects.GetContent(dr)
-
+ o1Content, err := objects.ExtractContent(dr)
+ if err != nil {
+ t.Error(err)
+ return
+ }
if string(o2Content) != string(o1Content) {
t.Errorf("Copy failed. Expected\n%s\nand got\n%s", string(o1Content), string(o2Content))
return
@@ -341,7 +350,7 @@
t.Error(err)
return
}
- om := objects.GetMetadata(gr)
+ om := objects.ExtractMetadata(gr)
for k := range metadata {
if om[k] != metadata[strings.Title(k)] {
t.Errorf("Expected custom metadata with key: %s", k)
diff --git a/openstack/storage/v1/accounts/accounts.go b/openstack/storage/v1/accounts/accounts.go
index cb72072..ae8ba19 100644
--- a/openstack/storage/v1/accounts/accounts.go
+++ b/openstack/storage/v1/accounts/accounts.go
@@ -13,11 +13,11 @@
Headers map[string]string
}
-// 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 metatdata associated with the account.
-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-Account-Meta-") {
key := strings.TrimPrefix(k, "X-Account-Meta-")
metadata[key] = v[0]
diff --git a/openstack/storage/v1/accounts/requests.go b/openstack/storage/v1/accounts/requests.go
index 08f1f3c..d5afbcd 100644
--- a/openstack/storage/v1/accounts/requests.go
+++ b/openstack/storage/v1/accounts/requests.go
@@ -3,9 +3,10 @@
import (
"github.com/racker/perigee"
storage "github.com/rackspace/gophercloud/openstack/storage/v1"
+ "net/http"
)
-type GetResult *perigee.Response
+type GetResult *http.Response
// Update is a function that creates, updates, or deletes an account's metadata.
func Update(c *storage.Client, opts UpdateOpts) error {
@@ -30,7 +31,7 @@
}
// Get is a function that retrieves an account's metadata. 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 {
@@ -46,5 +47,5 @@
MoreHeaders: h,
OkCodes: []int{204},
})
- return resp, err
+ return &resp.HttpResponse, err
}
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
}
diff --git a/openstack/storage/v1/objects/objects.go b/openstack/storage/v1/objects/objects.go
index 33bad29..9575e0f 100644
--- a/openstack/storage/v1/objects/objects.go
+++ b/openstack/storage/v1/objects/objects.go
@@ -3,6 +3,7 @@
import (
"bytes"
"encoding/json"
+ "io/ioutil"
"strings"
)
@@ -59,34 +60,48 @@
Headers 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 objects' information.
-func GetInfo(lr ListResult) ([]Object, error) {
+func ExtractInfo(lr ListResult) ([]Object, error) {
var oi []Object
- err := json.Unmarshal(lr.JsonResult, &oi)
+ defer lr.Body.Close()
+ body, err := ioutil.ReadAll(lr.Body)
+ if err != nil {
+ return oi, err
+ }
+ err = json.Unmarshal(body, &oi)
return oi, 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 objects' names.
-func GetNames(lr ListResult) []string {
- jr := string(lr.JsonResult)
- ons := strings.Split(jr, "\n")
+func ExtractNames(lr ListResult) ([]string, error) {
+ var ons []string
+ defer lr.Body.Close()
+ body, err := ioutil.ReadAll(lr.Body)
+ if err != nil {
+ return ons, err
+ }
+ jr := string(body)
+ ons = strings.Split(jr, "\n")
ons = ons[:len(ons)-1]
- return ons
+ return ons, nil
}
-// GetContent is a function that takes a DownloadResult (of type *perigee.Response)
+// ExtractContent is a function that takes a DownloadResult (of type *http.Response)
// and returns the object's content.
-func GetContent(dr DownloadResult) []byte {
- return dr.JsonResult
+func ExtractContent(dr DownloadResult) ([]byte, error) {
+ var body []byte
+ defer dr.Body.Close()
+ body, err := ioutil.ReadAll(dr.Body)
+ return body, err
}
-// GetMetadata is a function that takes a GetResult (of type *perifee.Response)
+// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
// and returns the custom metadata associated with the object.
-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-Object-Meta-") {
key := strings.TrimPrefix(k, "X-Object-Meta-")
metadata[key] = v[0]
diff --git a/openstack/storage/v1/objects/requests.go b/openstack/storage/v1/objects/requests.go
index fbcbe1f..615a59d 100644
--- a/openstack/storage/v1/objects/requests.go
+++ b/openstack/storage/v1/objects/requests.go
@@ -2,19 +2,19 @@
import (
"fmt"
-
"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 DownloadResult *perigee.Response
-type GetResult *perigee.Response
+type ListResult *http.Response
+type DownloadResult *http.Response
+type GetResult *http.Response
// List is a function that retrieves all objects in a container. It also returns the details
// for the container. To extract only the object 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 := ""
@@ -31,16 +31,15 @@
url := c.GetContainerURL(opts.Container) + 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
}
// Download is a function that retrieves the content and metadata for an object.
-// To extract just the content, pass the DownloadResult response to the GetContent
+// To extract just the content, pass the DownloadResult response to the ExtractContent
// function.
func Download(c *storage.Client, opts DownloadOpts) (DownloadResult, error) {
h, err := c.GetHeaders()
@@ -56,11 +55,10 @@
url := c.GetObjectURL(opts.Container, opts.Name) + query
resp, err := perigee.Request("GET", url, perigee.Options{
- Results: true,
MoreHeaders: h,
OkCodes: []int{200},
})
- return resp, err
+ return &resp.HttpResponse, err
}
// Create is a function that creates a new object or replaces an existing object.
@@ -139,7 +137,7 @@
}
// Get is a function that retrieves the metadata of an object. 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 {
@@ -155,7 +153,7 @@
MoreHeaders: h,
OkCodes: []int{204},
})
- return resp, err
+ return &resp.HttpResponse, err
}
// Update is a function that creates, updates, or deletes an object's metadata.