Use CommonResult for images.
diff --git a/openstack/compute/v2/images/requests.go b/openstack/compute/v2/images/requests.go
index 8736382..1de3187 100644
--- a/openstack/compute/v2/images/requests.go
+++ b/openstack/compute/v2/images/requests.go
@@ -33,10 +33,6 @@
return images[len(images)-1].ID, nil
}
-// GetResult opaquely stores the result of a Get call.
-// Use ExtractImage() to translate it into this provider's version of an Image structure.
-type GetResult map[string]interface{}
-
// List enumerates the available images.
func List(client *gophercloud.ServiceClient) pagination.Pager {
createPage := func(r pagination.LastHTTPResponse) pagination.Page {
@@ -50,12 +46,12 @@
// Get acquires additional detail about a specific image by ID.
// Use ExtractImage() to intepret the result as an openstack Image.
-func Get(client *gophercloud.ServiceClient, id string) (GetResult, error) {
+func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
- _, err := perigee.Request("GET", getImageURL(client, id), perigee.Options{
+ _, result.Err = perigee.Request("GET", getImageURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
- Results: &result,
+ Results: &result.Resp,
OkCodes: []int{200},
})
- return result, err
+ return result
}
diff --git a/openstack/compute/v2/images/images_test.go b/openstack/compute/v2/images/requests_test.go
similarity index 95%
rename from openstack/compute/v2/images/images_test.go
rename to openstack/compute/v2/images/requests_test.go
index 0dfae1e..396c21f 100644
--- a/openstack/compute/v2/images/images_test.go
+++ b/openstack/compute/v2/images/requests_test.go
@@ -146,16 +146,12 @@
})
client := serviceClient()
- result, err := Get(client, "12345678")
+ actual, err := Get(client, "12345678").Extract()
if err != nil {
t.Fatalf("Unexpected error from Get: %v", err)
}
- actual, err := ExtractImage(result)
- if err != nil {
- t.Fatalf("Unexpected error extracting image: %v", err)
- }
- expected := Image{
+ expected := &Image{
Status: "ACTIVE",
Updated: "2014-09-23T12:54:56Z",
ID: "f3e4a95d-1f4f-4989-97ce-f3a1fb8c04d7",
diff --git a/openstack/compute/v2/images/images.go b/openstack/compute/v2/images/results.go
similarity index 74%
rename from openstack/compute/v2/images/images.go
rename to openstack/compute/v2/images/results.go
index 76143d8..981cccd 100644
--- a/openstack/compute/v2/images/images.go
+++ b/openstack/compute/v2/images/results.go
@@ -2,9 +2,29 @@
import (
"github.com/mitchellh/mapstructure"
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
+// GetResult temporarily stores a Get response.
+type GetResult struct {
+ gophercloud.CommonResult
+}
+
+// Extract interprets a GetResult as an Image.
+func (gr GetResult) Extract() (*Image, error) {
+ if gr.Err != nil {
+ return nil, gr.Err
+ }
+
+ var decoded struct {
+ Image Image `mapstructure:"image"`
+ }
+
+ err := mapstructure.Decode(gr.Resp, &decoded)
+ return &decoded.Image, err
+}
+
// Image is used for JSON (un)marshalling.
// It provides a description of an OS image.
type Image struct {
@@ -38,13 +58,3 @@
err := mapstructure.Decode(casted, &results)
return results.Images, err
}
-
-// ExtractImage converts the result of a Get call into a more usable Image structure.
-func ExtractImage(result GetResult) (Image, error) {
- var decoded struct {
- Image Image `mapstructure:"image"`
- }
-
- err := mapstructure.Decode(result, &decoded)
- return decoded.Image, err
-}