Merge remote-tracking branch 'upstream/v0.2.0' into stale-refs
diff --git a/docs/identity/v2/index.md b/docs/identity/v2/index.md
deleted file mode 100644
index c0e82bd..0000000
--- a/docs/identity/v2/index.md
+++ /dev/null
@@ -1,60 +0,0 @@
----
-layout: page
-title: Getting Started with Identity v2
----
-
-## Tokens
-
-A token is an arbitrary bit of text that is used to access resources. Each
-token has a scope that describes which resources are accessible with it. A
-token may be revoked at anytime and is valid for a finite duration.
-
-### Generate a token
-
-The nature of required and optional auth options will depend on your provider,
-but generally the `Username` and `IdentityEndpoint` fields are always
-required. Some providers will insist on a `Password` instead of an `APIKey`,
-others will prefer `TenantID` over `TenantName` - so it is always worth
-checking before writing your implementation in Go.
-
-{% highlight go %}
-import "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
-
-opts := tokens.AuthOptions{
- IdentityEndpoint: "{identityURL}",
- Username: "{username}",
- APIKey: "{apiKey}",
-}
-
-token, err := tokens.Create(client, opts).Extract()
-{% endhighlight %}
-
-## Tenants
-
-A tenant is a container used to group or isolate API resources. Depending on
-the provider, a tenant can map to a customer, account, organization, or project.
-
-### List tenants
-
-{% highlight go %}
-import (
- "github.com/rackspace/gophercloud/pagination"
- "github.com/rackspace/gophercloud/openstack/identity/v2/tenants"
-)
-
-// We have the option of filtering the tenant list. If we want the full
-// collection, leave it as an empty struct
-opts := tenants.ListOpts{Limit: 10}
-
-// Retrieve a pager (i.e. a paginated collection)
-pager := tenants.List(client, opts)
-
-// Define an anonymous function to be executed on each page's iteration
-err := pager.EachPage(func(page pagination.Page) (bool, error) {
- tenantList, err := tenants.ExtractTenants(page)
-
- for _, t := range tenantList {
- // "t" will be a tenants.Tenant
- }
-})
-{% endhighlight %}
diff --git a/docs/identity/v3/index.md b/docs/identity/v3/index.md
deleted file mode 100644
index ab2da67..0000000
--- a/docs/identity/v3/index.md
+++ /dev/null
@@ -1,36 +0,0 @@
----
-layout: page
-title: Getting Started with Identity v3
----
-
-## Tokens
-
-### Generate a token
-
-### Get a token
-
-### Validate token
-
-### Revoke token
-
-## Endpoints
-
-### Create an endpoint
-
-### List endpoints
-
-### Update endpoint
-
-### Delete endpoint
-
-## Services
-
-### Create a service
-
-### List services
-
-### Get a service
-
-### Update service
-
-### Delete service
diff --git a/openstack/blockstorage/v1/apiversions/requests.go b/openstack/blockstorage/v1/apiversions/requests.go
index 79a939c..a56f249 100644
--- a/openstack/blockstorage/v1/apiversions/requests.go
+++ b/openstack/blockstorage/v1/apiversions/requests.go
@@ -9,7 +9,7 @@
// List lists all the Cinder API versions available to end-users.
func List(c *gophercloud.ServiceClient) pagination.Pager {
- return pagination.NewPager(c, listURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
+ return pagination.NewPager(c, listURL(c), func(r pagination.PageResult) pagination.Page {
return APIVersionPage{pagination.SinglePageBase(r)}
})
}
@@ -21,7 +21,7 @@
_, err := perigee.Request("GET", getURL(client, v), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
- Results: &res.Resp,
+ Results: &res.Body,
})
res.Err = err
return res
diff --git a/openstack/blockstorage/v1/apiversions/results.go b/openstack/blockstorage/v1/apiversions/results.go
index ea2f7f5..7b0df11 100644
--- a/openstack/blockstorage/v1/apiversions/results.go
+++ b/openstack/blockstorage/v1/apiversions/results.go
@@ -43,7 +43,7 @@
// GetResult represents the result of a get operation.
type GetResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts an API version resource.
@@ -52,7 +52,7 @@
Version *APIVersion `mapstructure:"version"`
}
- err := mapstructure.Decode(r.Resp, &resp)
+ err := mapstructure.Decode(r.Body, &resp)
return resp.Version, err
}
diff --git a/openstack/blockstorage/v1/snapshots/requests.go b/openstack/blockstorage/v1/snapshots/requests.go
index 7fac925..49b637a 100644
--- a/openstack/blockstorage/v1/snapshots/requests.go
+++ b/openstack/blockstorage/v1/snapshots/requests.go
@@ -73,7 +73,7 @@
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200, 201},
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
})
return res
}
@@ -92,7 +92,7 @@
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
_, res.Err = perigee.Request("GET", getURL(client, id), perigee.Options{
- Results: &res.Resp,
+ Results: &res.Body,
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
})
@@ -134,7 +134,7 @@
url += query
}
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
+ createPage := func(r pagination.PageResult) pagination.Page {
return ListResult{pagination.SinglePageBase(r)}
}
return pagination.NewPager(client, url, createPage)
@@ -181,7 +181,7 @@
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
})
return res
}
diff --git a/openstack/blockstorage/v1/snapshots/results.go b/openstack/blockstorage/v1/snapshots/results.go
index dc94a32..d414a7d 100644
--- a/openstack/blockstorage/v1/snapshots/results.go
+++ b/openstack/blockstorage/v1/snapshots/results.go
@@ -11,28 +11,40 @@
type Snapshot struct {
// Currect status of the Snapshot.
Status string `mapstructure:"status"`
+
// Display name.
Name string `mapstructure:"display_name"`
+
// Instances onto which the Snapshot is attached.
Attachments []string `mapstructure:"attachments"`
+
// Logical group.
AvailabilityZone string `mapstructure:"availability_zone"`
+
// Is the Snapshot bootable?
Bootable string `mapstructure:"bootable"`
+
// Date created.
CreatedAt string `mapstructure:"created_at"`
+
// Display description.
Description string `mapstructure:"display_discription"`
+
// See VolumeType object for more information.
VolumeType string `mapstructure:"volume_type"`
+
// ID of the Snapshot from which this Snapshot was created.
SnapshotID string `mapstructure:"snapshot_id"`
+
// ID of the Volume from which this Snapshot was created.
VolumeID string `mapstructure:"volume_id"`
+
// User-defined key-value pairs.
Metadata map[string]string `mapstructure:"metadata"`
+
// Unique identifier.
ID string `mapstructure:"id"`
+
// Size of the Snapshot, in GB.
Size int `mapstructure:"size"`
}
@@ -82,13 +94,12 @@
return nil, r.Err
}
- m := r.Resp["metadata"].(map[string]interface{})
-
- return m, nil
+ m := r.Body.(map[string]interface{})["metadata"]
+ return m.(map[string]interface{}), nil
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract will get the Snapshot object out of the commonResult object.
@@ -101,7 +112,7 @@
Snapshot *Snapshot `json:"snapshot"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Snapshot, err
}
diff --git a/openstack/blockstorage/v1/volumes/requests.go b/openstack/blockstorage/v1/volumes/requests.go
index 042a33e..2b3aaeb 100644
--- a/openstack/blockstorage/v1/volumes/requests.go
+++ b/openstack/blockstorage/v1/volumes/requests.go
@@ -88,7 +88,7 @@
_, res.Err = perigee.Request("POST", createURL(client), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200, 201},
})
return res
@@ -108,7 +108,7 @@
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
_, res.Err = perigee.Request("GET", getURL(client, id), perigee.Options{
- Results: &res.Resp,
+ Results: &res.Body,
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
})
@@ -153,7 +153,7 @@
}
url += query
}
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
+ createPage := func(r pagination.PageResult) pagination.Page {
return ListResult{pagination.SinglePageBase(r)}
}
return pagination.NewPager(client, url, createPage)
@@ -210,7 +210,7 @@
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
})
return res
}
diff --git a/openstack/blockstorage/v1/volumes/results.go b/openstack/blockstorage/v1/volumes/results.go
index 78eb6c1..7215daf 100644
--- a/openstack/blockstorage/v1/volumes/results.go
+++ b/openstack/blockstorage/v1/volumes/results.go
@@ -64,7 +64,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract will get the Volume object out of the commonResult object.
@@ -77,7 +77,7 @@
Volume *Volume `json:"volume"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Volume, err
}
diff --git a/openstack/blockstorage/v1/volumetypes/requests.go b/openstack/blockstorage/v1/volumetypes/requests.go
index d4f880f..c1c3dd5 100644
--- a/openstack/blockstorage/v1/volumetypes/requests.go
+++ b/openstack/blockstorage/v1/volumetypes/requests.go
@@ -49,7 +49,7 @@
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200, 201},
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
})
return res
}
@@ -70,7 +70,7 @@
_, err := perigee.Request("GET", getURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
- Results: &res.Resp,
+ Results: &res.Body,
})
res.Err = err
return res
@@ -78,7 +78,7 @@
// List returns all volume types.
func List(client *gophercloud.ServiceClient) pagination.Pager {
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
+ createPage := func(r pagination.PageResult) pagination.Page {
return ListResult{pagination.SinglePageBase(r)}
}
diff --git a/openstack/blockstorage/v1/volumetypes/results.go b/openstack/blockstorage/v1/volumetypes/results.go
index 77cc1f5..a13f7c1 100644
--- a/openstack/blockstorage/v1/volumetypes/results.go
+++ b/openstack/blockstorage/v1/volumetypes/results.go
@@ -48,7 +48,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract will get the Volume Type object out of the commonResult object.
@@ -61,7 +61,7 @@
VolumeType *VolumeType `json:"volume_type" mapstructure:"volume_type"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.VolumeType, err
}
diff --git a/openstack/common/extensions/requests.go b/openstack/common/extensions/requests.go
index 000151b..f1b9c22 100755
--- a/openstack/common/extensions/requests.go
+++ b/openstack/common/extensions/requests.go
@@ -11,7 +11,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", ExtensionURL(c, alias), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -20,7 +20,7 @@
// List returns a Pager which allows you to iterate over the full collection of extensions.
// It does not accept query parameters.
func List(c *gophercloud.ServiceClient) pagination.Pager {
- return pagination.NewPager(c, ListExtensionURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
+ return pagination.NewPager(c, ListExtensionURL(c), func(r pagination.PageResult) pagination.Page {
return ExtensionPage{pagination.SinglePageBase(r)}
})
}
diff --git a/openstack/common/extensions/results.go b/openstack/common/extensions/results.go
index 4827072..777d083 100755
--- a/openstack/common/extensions/results.go
+++ b/openstack/common/extensions/results.go
@@ -9,7 +9,7 @@
// GetResult temporarily stores the result of a Get call.
// Use its Extract() method to interpret it as an Extension.
type GetResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract interprets a GetResult as an Extension.
@@ -22,7 +22,7 @@
Extension *Extension `json:"extension"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Extension, err
}
diff --git a/openstack/compute/v2/flavors/requests.go b/openstack/compute/v2/flavors/requests.go
index 7af11fc..b77a79a 100644
--- a/openstack/compute/v2/flavors/requests.go
+++ b/openstack/compute/v2/flavors/requests.go
@@ -53,8 +53,8 @@
}
url += query
}
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- return FlavorPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return FlavorPage{pagination.LinkedPageBase{PageResult: r}}
}
return pagination.NewPager(client, url, createPage)
@@ -65,7 +65,7 @@
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var gr GetResult
gr.Err = perigee.Get(getURL(client, id), perigee.Options{
- Results: &gr.Resp,
+ Results: &gr.Body,
MoreHeaders: client.Provider.AuthenticatedHeaders(),
})
return gr
diff --git a/openstack/compute/v2/flavors/results.go b/openstack/compute/v2/flavors/results.go
index 1e274e3..389bd7f 100644
--- a/openstack/compute/v2/flavors/results.go
+++ b/openstack/compute/v2/flavors/results.go
@@ -14,7 +14,7 @@
// GetResult temporarily holds the reponse from a Get call.
type GetResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract provides access to the individual Flavor returned by the Get function.
@@ -35,7 +35,7 @@
if err != nil {
return nil, err
}
- err = decoder.Decode(gr.Resp)
+ err = decoder.Decode(gr.Body)
return &result.Flavor, err
}
diff --git a/openstack/compute/v2/images/requests.go b/openstack/compute/v2/images/requests.go
index 603909c..4f93ffa 100644
--- a/openstack/compute/v2/images/requests.go
+++ b/openstack/compute/v2/images/requests.go
@@ -51,8 +51,8 @@
url += query
}
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- return ImagePage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return ImagePage{pagination.LinkedPageBase{PageResult: r}}
}
return pagination.NewPager(client, url, createPage)
@@ -64,7 +64,7 @@
var result GetResult
_, result.Err = perigee.Request("GET", getURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{200},
})
return result
diff --git a/openstack/compute/v2/images/results.go b/openstack/compute/v2/images/results.go
index 3c22eeb..493d511 100644
--- a/openstack/compute/v2/images/results.go
+++ b/openstack/compute/v2/images/results.go
@@ -8,7 +8,7 @@
// GetResult temporarily stores a Get response.
type GetResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract interprets a GetResult as an Image.
@@ -21,7 +21,7 @@
Image Image `mapstructure:"image"`
}
- err := mapstructure.Decode(gr.Resp, &decoded)
+ err := mapstructure.Decode(gr.Body, &decoded)
return &decoded.Image, err
}
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index 0b38175..749b1f8 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -69,8 +69,8 @@
url += query
}
- createPageFn := func(r pagination.LastHTTPResponse) pagination.Page {
- return ServerPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ createPageFn := func(r pagination.PageResult) pagination.Page {
+ return ServerPage{pagination.LinkedPageBase{PageResult: r}}
}
return pagination.NewPager(client, url, createPageFn)
@@ -188,7 +188,7 @@
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
var result CreateResult
_, result.Err = perigee.Request("POST", listURL(client), perigee.Options{
- Results: &result.Resp,
+ Results: &result.Body,
ReqBody: opts.ToServerCreateMap(),
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{202},
@@ -209,7 +209,7 @@
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
_, result.Err = perigee.Request("GET", getURL(client, id), perigee.Options{
- Results: &result.Resp,
+ Results: &result.Body,
MoreHeaders: client.Provider.AuthenticatedHeaders(),
})
return result
@@ -253,7 +253,7 @@
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult {
var result UpdateResult
_, result.Err = perigee.Request("PUT", updateURL(client, id), perigee.Options{
- Results: &result.Resp,
+ Results: &result.Body,
ReqBody: opts.ToServerUpdateMap(),
MoreHeaders: client.Provider.AuthenticatedHeaders(),
})
@@ -446,7 +446,7 @@
_, result.Err = perigee.Request("POST", actionURL(client, id), perigee.Options{
ReqBody: &reqBody,
- Results: &result.Resp,
+ Results: &result.Body,
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{202},
})
diff --git a/openstack/compute/v2/servers/results.go b/openstack/compute/v2/servers/results.go
index 1402d8a..1d85ec0 100644
--- a/openstack/compute/v2/servers/results.go
+++ b/openstack/compute/v2/servers/results.go
@@ -7,7 +7,7 @@
)
type serverResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract interprets any serverResult as a Server, if possible.
@@ -20,7 +20,7 @@
Server Server `mapstructure:"server"`
}
- err := mapstructure.Decode(r.Resp, &response)
+ err := mapstructure.Decode(r.Body, &response)
return &response.Server, err
}
diff --git a/openstack/identity/v2/extensions/delegate.go b/openstack/identity/v2/extensions/delegate.go
index cee275f..fd6e80e 100644
--- a/openstack/identity/v2/extensions/delegate.go
+++ b/openstack/identity/v2/extensions/delegate.go
@@ -44,7 +44,7 @@
// List returns a Pager which allows you to iterate over the full collection of extensions.
// It does not accept query parameters.
func List(c *gophercloud.ServiceClient) pagination.Pager {
- return common.List(c).WithPageCreator(func(r pagination.LastHTTPResponse) pagination.Page {
+ return common.List(c).WithPageCreator(func(r pagination.PageResult) pagination.Page {
return ExtensionPage{
ExtensionPage: common.ExtensionPage{SinglePageBase: pagination.SinglePageBase(r)},
}
diff --git a/openstack/identity/v2/tenants/requests.go b/openstack/identity/v2/tenants/requests.go
index 5ffeaa7..5a359f5 100644
--- a/openstack/identity/v2/tenants/requests.go
+++ b/openstack/identity/v2/tenants/requests.go
@@ -16,8 +16,8 @@
// List enumerates the Tenants to which the current token has access.
func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager {
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- return TenantPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return TenantPage{pagination.LinkedPageBase{PageResult: r}}
}
url := listURL(client)
diff --git a/openstack/identity/v2/tokens/requests.go b/openstack/identity/v2/tokens/requests.go
index c25a72b..87c923a 100644
--- a/openstack/identity/v2/tokens/requests.go
+++ b/openstack/identity/v2/tokens/requests.go
@@ -74,13 +74,13 @@
func Create(client *gophercloud.ServiceClient, auth AuthOptionsBuilder) CreateResult {
request, err := auth.ToTokenCreateMap()
if err != nil {
- return CreateResult{gophercloud.CommonResult{Err: err}}
+ return CreateResult{gophercloud.Result{Err: err}}
}
var result CreateResult
_, result.Err = perigee.Request("POST", CreateURL(client), perigee.Options{
ReqBody: &request,
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{200, 203},
})
return result
diff --git a/openstack/identity/v2/tokens/results.go b/openstack/identity/v2/tokens/results.go
index e88b2c7..1eddb9d 100644
--- a/openstack/identity/v2/tokens/results.go
+++ b/openstack/identity/v2/tokens/results.go
@@ -71,7 +71,7 @@
// CreateResult defers the interpretation of a created token.
// Use ExtractToken() to interpret it as a Token, or ExtractServiceCatalog() to interpret it as a service catalog.
type CreateResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// ExtractToken returns the just-created Token from a CreateResult.
@@ -90,7 +90,7 @@
} `mapstructure:"access"`
}
- err := mapstructure.Decode(result.Resp, &response)
+ err := mapstructure.Decode(result.Body, &response)
if err != nil {
return nil, err
}
@@ -119,7 +119,7 @@
} `mapstructure:"access"`
}
- err := mapstructure.Decode(result.Resp, &response)
+ err := mapstructure.Decode(result.Body, &response)
if err != nil {
return nil, err
}
@@ -129,5 +129,5 @@
// createErr quickly packs an error in a CreateResult.
func createErr(err error) CreateResult {
- return CreateResult{gophercloud.CommonResult{Err: err}}
+ return CreateResult{gophercloud.Result{Err: err}}
}
diff --git a/openstack/identity/v3/endpoints/requests.go b/openstack/identity/v3/endpoints/requests.go
index eb52573..f05cae7 100644
--- a/openstack/identity/v3/endpoints/requests.go
+++ b/openstack/identity/v3/endpoints/requests.go
@@ -63,7 +63,7 @@
_, result.Err = perigee.Request("POST", listURL(client), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{201},
})
return result
@@ -94,8 +94,8 @@
q["per_page"] = strconv.Itoa(opts.Page)
}
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- return EndpointPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return EndpointPage{pagination.LinkedPageBase{PageResult: r}}
}
u := listURL(client) + utils.BuildQuery(q)
@@ -128,7 +128,7 @@
_, result.Err = perigee.Request("PATCH", endpointURL(client, endpointID), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{200},
})
return result
diff --git a/openstack/identity/v3/endpoints/results.go b/openstack/identity/v3/endpoints/results.go
index d1c2472..f559b9a 100644
--- a/openstack/identity/v3/endpoints/results.go
+++ b/openstack/identity/v3/endpoints/results.go
@@ -7,7 +7,7 @@
)
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract interprets a GetResult, CreateResult or UpdateResult as a concrete Endpoint.
@@ -21,7 +21,7 @@
Endpoint `json:"endpoint"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return &res.Endpoint, err
}
@@ -33,7 +33,7 @@
// createErr quickly wraps an error in a CreateResult.
func createErr(err error) CreateResult {
- return CreateResult{commonResult{gophercloud.CommonResult{Err: err}}}
+ return CreateResult{commonResult{gophercloud.Result{Err: err}}}
}
// UpdateResult is the deferred result of an Update call.
diff --git a/openstack/identity/v3/services/requests.go b/openstack/identity/v3/services/requests.go
index 7816aca..a3eefea 100644
--- a/openstack/identity/v3/services/requests.go
+++ b/openstack/identity/v3/services/requests.go
@@ -25,7 +25,7 @@
_, result.Err = perigee.Request("POST", listURL(client), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
ReqBody: &req,
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{201},
})
return result
@@ -52,8 +52,8 @@
}
u := listURL(client) + utils.BuildQuery(q)
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- return ServicePage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ createPage := func(r pagination.PageResult) pagination.Page {
+ return ServicePage{pagination.LinkedPageBase{PageResult: r}}
}
return pagination.NewPager(client, u, createPage)
@@ -64,7 +64,7 @@
var result GetResult
_, result.Err = perigee.Request("GET", serviceURL(client, serviceID), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{200},
})
return result
@@ -82,7 +82,7 @@
_, result.Err = perigee.Request("PATCH", serviceURL(client, serviceID), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
ReqBody: &req,
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{200},
})
return result
diff --git a/openstack/identity/v3/services/results.go b/openstack/identity/v3/services/results.go
index e4e068b..dcd7fe2 100644
--- a/openstack/identity/v3/services/results.go
+++ b/openstack/identity/v3/services/results.go
@@ -8,7 +8,7 @@
)
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract interprets a GetResult, CreateResult or UpdateResult as a concrete Service.
@@ -22,7 +22,7 @@
Service `json:"service"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return &res.Service, err
}
diff --git a/openstack/identity/v3/tokens/requests.go b/openstack/identity/v3/tokens/requests.go
index c8587b6..dfef0ce 100644
--- a/openstack/identity/v3/tokens/requests.go
+++ b/openstack/identity/v3/tokens/requests.go
@@ -236,13 +236,13 @@
var response *perigee.Response
response, result.Err = perigee.Request("POST", tokenURL(c), perigee.Options{
ReqBody: &req,
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{201},
})
if result.Err != nil {
return result
}
- result.header = response.HttpResponse.Header
+ result.Header = response.HttpResponse.Header
return result
}
@@ -252,13 +252,13 @@
var response *perigee.Response
response, result.Err = perigee.Request("GET", tokenURL(c), perigee.Options{
MoreHeaders: subjectTokenHeaders(c, token),
- Results: &result.Resp,
+ Results: &result.Body,
OkCodes: []int{200, 203},
})
if result.Err != nil {
return result
}
- result.header = response.HttpResponse.Header
+ result.Header = response.HttpResponse.Header
return result
}
diff --git a/openstack/identity/v3/tokens/results.go b/openstack/identity/v3/tokens/results.go
index 1be98cb..c31c52f 100644
--- a/openstack/identity/v3/tokens/results.go
+++ b/openstack/identity/v3/tokens/results.go
@@ -1,7 +1,6 @@
package tokens
import (
- "net/http"
"time"
"github.com/mitchellh/mapstructure"
@@ -10,10 +9,7 @@
// commonResult is the deferred result of a Create or a Get call.
type commonResult struct {
- gophercloud.CommonResult
-
- // header stores the headers from the original HTTP response because token responses are returned in an X-Subject-Token header.
- header http.Header
+ gophercloud.Result
}
// Extract interprets a commonResult as a Token.
@@ -31,9 +27,9 @@
var token Token
// Parse the token itself from the stored headers.
- token.ID = r.header.Get("X-Subject-Token")
+ token.ID = r.Header.Get("X-Subject-Token")
- err := mapstructure.Decode(r.Resp, &response)
+ err := mapstructure.Decode(r.Body, &response)
if err != nil {
return nil, err
}
@@ -52,10 +48,7 @@
// createErr quickly creates a CreateResult that reports an error.
func createErr(err error) CreateResult {
return CreateResult{
- commonResult: commonResult{
- CommonResult: gophercloud.CommonResult{Err: err},
- header: nil,
- },
+ commonResult: commonResult{Result: gophercloud.Result{Err: err}},
}
}
diff --git a/openstack/networking/v2/apiversions/requests.go b/openstack/networking/v2/apiversions/requests.go
index b653f51..9fb6de1 100644
--- a/openstack/networking/v2/apiversions/requests.go
+++ b/openstack/networking/v2/apiversions/requests.go
@@ -7,7 +7,7 @@
// ListVersions lists all the Neutron API versions available to end-users
func ListVersions(c *gophercloud.ServiceClient) pagination.Pager {
- return pagination.NewPager(c, apiVersionsURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
+ return pagination.NewPager(c, apiVersionsURL(c), func(r pagination.PageResult) pagination.Page {
return APIVersionPage{pagination.SinglePageBase(r)}
})
}
@@ -15,7 +15,7 @@
// ListVersionResources lists all of the different API resources for a particular
// API versions. Typical resources for Neutron might be: networks, subnets, etc.
func ListVersionResources(c *gophercloud.ServiceClient, v string) pagination.Pager {
- return pagination.NewPager(c, apiInfoURL(c, v), func(r pagination.LastHTTPResponse) pagination.Page {
+ return pagination.NewPager(c, apiInfoURL(c, v), func(r pagination.PageResult) pagination.Page {
return APIVersionResourcePage{pagination.SinglePageBase(r)}
})
}
diff --git a/openstack/networking/v2/extensions/external/results.go b/openstack/networking/v2/extensions/external/results.go
index 47f7258..1c173c0 100644
--- a/openstack/networking/v2/extensions/external/results.go
+++ b/openstack/networking/v2/extensions/external/results.go
@@ -35,7 +35,7 @@
External bool `mapstructure:"router:external" json:"router:external"`
}
-func commonExtract(e error, response map[string]interface{}) (*NetworkExternal, error) {
+func commonExtract(e error, response interface{}) (*NetworkExternal, error) {
if e != nil {
return nil, e
}
@@ -52,19 +52,19 @@
// ExtractGet decorates a GetResult struct returned from a networks.Get()
// function with extended attributes.
func ExtractGet(r networks.GetResult) (*NetworkExternal, error) {
- return commonExtract(r.Err, r.Resp)
+ return commonExtract(r.Err, r.Body)
}
// ExtractCreate decorates a CreateResult struct returned from a networks.Create()
// function with extended attributes.
func ExtractCreate(r networks.CreateResult) (*NetworkExternal, error) {
- return commonExtract(r.Err, r.Resp)
+ return commonExtract(r.Err, r.Body)
}
// ExtractUpdate decorates a UpdateResult struct returned from a
// networks.Update() function with extended attributes.
func ExtractUpdate(r networks.UpdateResult) (*NetworkExternal, error) {
- return commonExtract(r.Err, r.Resp)
+ return commonExtract(r.Err, r.Body)
}
// ExtractList accepts a Page struct, specifically a NetworkPage struct, and
diff --git a/openstack/networking/v2/extensions/layer3/floatingips/requests.go b/openstack/networking/v2/extensions/layer3/floatingips/requests.go
index 22a6cae..a0a17fd 100644
--- a/openstack/networking/v2/extensions/layer3/floatingips/requests.go
+++ b/openstack/networking/v2/extensions/layer3/floatingips/requests.go
@@ -35,8 +35,8 @@
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return FloatingIPPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return FloatingIPPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -117,7 +117,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
@@ -129,7 +129,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -170,7 +170,7 @@
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
diff --git a/openstack/networking/v2/extensions/layer3/floatingips/results.go b/openstack/networking/v2/extensions/layer3/floatingips/results.go
index 43892f0..df3a63f 100644
--- a/openstack/networking/v2/extensions/layer3/floatingips/results.go
+++ b/openstack/networking/v2/extensions/layer3/floatingips/results.go
@@ -40,7 +40,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract a result and extracts a FloatingIP resource.
@@ -53,7 +53,7 @@
FloatingIP *FloatingIP `json:"floatingip"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
if err != nil {
return nil, fmt.Errorf("Error decoding Neutron floating IP: %v", err)
}
diff --git a/openstack/networking/v2/extensions/layer3/routers/requests.go b/openstack/networking/v2/extensions/layer3/routers/requests.go
index dbfd36b..52afc4f 100755
--- a/openstack/networking/v2/extensions/layer3/routers/requests.go
+++ b/openstack/networking/v2/extensions/layer3/routers/requests.go
@@ -37,8 +37,8 @@
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return RouterPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return RouterPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -85,7 +85,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
return res
@@ -96,7 +96,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -139,7 +139,7 @@
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
@@ -205,7 +205,7 @@
_, res.Err = perigee.Request("PUT", addInterfaceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &body,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
@@ -238,7 +238,7 @@
_, res.Err = perigee.Request("PUT", removeInterfaceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &body,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
diff --git a/openstack/networking/v2/extensions/layer3/routers/results.go b/openstack/networking/v2/extensions/layer3/routers/results.go
index eae647f..ba2f757 100755
--- a/openstack/networking/v2/extensions/layer3/routers/results.go
+++ b/openstack/networking/v2/extensions/layer3/routers/results.go
@@ -87,7 +87,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a router.
@@ -100,7 +100,7 @@
Router *Router `json:"router"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Router, err
}
@@ -143,7 +143,7 @@
// InterfaceResult represents the result of interface operations, such as
// AddInterface() and RemoveInterface().
type InterfaceResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts an information struct.
@@ -153,7 +153,7 @@
}
var res *InterfaceInfo
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res, err
}
diff --git a/openstack/networking/v2/extensions/lbaas/members/requests.go b/openstack/networking/v2/extensions/lbaas/members/requests.go
index d095706..c13f0fe 100644
--- a/openstack/networking/v2/extensions/lbaas/members/requests.go
+++ b/openstack/networking/v2/extensions/lbaas/members/requests.go
@@ -38,8 +38,8 @@
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return MemberPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return MemberPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -83,7 +83,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
return res
@@ -94,7 +94,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -122,7 +122,7 @@
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
diff --git a/openstack/networking/v2/extensions/lbaas/members/results.go b/openstack/networking/v2/extensions/lbaas/members/results.go
index b006551..a4408e1 100644
--- a/openstack/networking/v2/extensions/lbaas/members/results.go
+++ b/openstack/networking/v2/extensions/lbaas/members/results.go
@@ -83,7 +83,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a router.
@@ -96,7 +96,7 @@
Member *Member `json:"member"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Member, err
}
diff --git a/openstack/networking/v2/extensions/lbaas/monitors/requests.go b/openstack/networking/v2/extensions/lbaas/monitors/requests.go
index fca7199..9f8ac9a 100644
--- a/openstack/networking/v2/extensions/lbaas/monitors/requests.go
+++ b/openstack/networking/v2/extensions/lbaas/monitors/requests.go
@@ -44,8 +44,8 @@
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return MonitorPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return MonitorPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -176,7 +176,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
@@ -188,7 +188,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -256,7 +256,7 @@
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200, 202},
})
diff --git a/openstack/networking/v2/extensions/lbaas/monitors/results.go b/openstack/networking/v2/extensions/lbaas/monitors/results.go
index 656ab1d..bd711f7 100644
--- a/openstack/networking/v2/extensions/lbaas/monitors/results.go
+++ b/openstack/networking/v2/extensions/lbaas/monitors/results.go
@@ -108,7 +108,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a monitor.
@@ -121,7 +121,7 @@
Monitor *Monitor `json:"health_monitor" mapstructure:"health_monitor"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Monitor, err
}
diff --git a/openstack/networking/v2/extensions/lbaas/pools/requests.go b/openstack/networking/v2/extensions/lbaas/pools/requests.go
index 2688350..6e5b87a 100644
--- a/openstack/networking/v2/extensions/lbaas/pools/requests.go
+++ b/openstack/networking/v2/extensions/lbaas/pools/requests.go
@@ -39,8 +39,8 @@
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return PoolPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return PoolPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -103,7 +103,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
return res
@@ -114,7 +114,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -151,7 +151,7 @@
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -186,7 +186,7 @@
_, res.Err = perigee.Request("POST", associateURL(c, poolID), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
return res
diff --git a/openstack/networking/v2/extensions/lbaas/pools/results.go b/openstack/networking/v2/extensions/lbaas/pools/results.go
index 4233176..3b1c66c 100644
--- a/openstack/networking/v2/extensions/lbaas/pools/results.go
+++ b/openstack/networking/v2/extensions/lbaas/pools/results.go
@@ -102,7 +102,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a router.
@@ -115,7 +115,7 @@
Pool *Pool `json:"pool"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Pool, err
}
diff --git a/openstack/networking/v2/extensions/lbaas/vips/requests.go b/openstack/networking/v2/extensions/lbaas/vips/requests.go
index ce4d9e4..6c4ee3d 100644
--- a/openstack/networking/v2/extensions/lbaas/vips/requests.go
+++ b/openstack/networking/v2/extensions/lbaas/vips/requests.go
@@ -56,8 +56,8 @@
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return VIPPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return VIPPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -182,7 +182,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
@@ -194,7 +194,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -255,7 +255,7 @@
_, res.Err = perigee.Request("PUT", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200, 202},
})
diff --git a/openstack/networking/v2/extensions/lbaas/vips/results.go b/openstack/networking/v2/extensions/lbaas/vips/results.go
index 5925adc..731edef 100644
--- a/openstack/networking/v2/extensions/lbaas/vips/results.go
+++ b/openstack/networking/v2/extensions/lbaas/vips/results.go
@@ -127,7 +127,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a router.
@@ -140,7 +140,7 @@
VirtualIP *VirtualIP `mapstructure:"vip" json:"vip"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.VirtualIP, err
}
diff --git a/openstack/networking/v2/extensions/provider/results.go b/openstack/networking/v2/extensions/provider/results.go
index 8fc21b4..3453584 100755
--- a/openstack/networking/v2/extensions/provider/results.go
+++ b/openstack/networking/v2/extensions/provider/results.go
@@ -73,7 +73,7 @@
Network *NetworkExtAttrs `json:"network"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Network, err
}
@@ -89,7 +89,7 @@
Network *NetworkExtAttrs `json:"network"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Network, err
}
@@ -105,7 +105,7 @@
Network *NetworkExtAttrs `json:"network"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Network, err
}
diff --git a/openstack/networking/v2/extensions/security/groups/requests.go b/openstack/networking/v2/extensions/security/groups/requests.go
index 6e9fe33..6b33e06 100644
--- a/openstack/networking/v2/extensions/security/groups/requests.go
+++ b/openstack/networking/v2/extensions/security/groups/requests.go
@@ -32,8 +32,8 @@
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return SecGroupPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return SecGroupPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -78,7 +78,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
@@ -90,7 +90,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
diff --git a/openstack/networking/v2/extensions/security/groups/results.go b/openstack/networking/v2/extensions/security/groups/results.go
index 617d690..3b256ef 100644
--- a/openstack/networking/v2/extensions/security/groups/results.go
+++ b/openstack/networking/v2/extensions/security/groups/results.go
@@ -74,7 +74,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a security group.
@@ -87,7 +87,7 @@
SecGroup *SecGroup `mapstructure:"security_group" json:"security_group"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.SecGroup, err
}
diff --git a/openstack/networking/v2/extensions/security/rules/requests.go b/openstack/networking/v2/extensions/security/rules/requests.go
index ea0f37d..f243572 100644
--- a/openstack/networking/v2/extensions/security/rules/requests.go
+++ b/openstack/networking/v2/extensions/security/rules/requests.go
@@ -39,8 +39,8 @@
return pagination.Pager{Err: err}
}
u := rootURL(c) + q.String()
- return pagination.NewPager(c, u, func(r pagination.LastHTTPResponse) pagination.Page {
- return SecGroupRulePage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page {
+ return SecGroupRulePage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -154,7 +154,7 @@
_, res.Err = perigee.Request("POST", rootURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
@@ -166,7 +166,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", resourceURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
diff --git a/openstack/networking/v2/extensions/security/rules/results.go b/openstack/networking/v2/extensions/security/rules/results.go
index ca8435e..29e8676 100644
--- a/openstack/networking/v2/extensions/security/rules/results.go
+++ b/openstack/networking/v2/extensions/security/rules/results.go
@@ -99,7 +99,7 @@
}
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a security rule.
@@ -112,7 +112,7 @@
SecGroupRule *SecGroupRule `mapstructure:"security_group_rule" json:"security_group_rule"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.SecGroupRule, err
}
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 8cfe4e0..a82eeb2 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -73,8 +73,8 @@
url += query
}
- return pagination.NewPager(c, url, func(r pagination.LastHTTPResponse) pagination.Page {
- return NetworkPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
+ return NetworkPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -83,7 +83,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", getURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -141,7 +141,7 @@
_, res.Err = perigee.Request("POST", createURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
return res
@@ -191,7 +191,7 @@
_, res.Err = perigee.Request("PUT", getURL(c, networkID), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200, 201},
})
diff --git a/openstack/networking/v2/networks/results.go b/openstack/networking/v2/networks/results.go
index e605fcf..6c32ebe 100644
--- a/openstack/networking/v2/networks/results.go
+++ b/openstack/networking/v2/networks/results.go
@@ -7,7 +7,7 @@
)
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a network resource.
@@ -20,7 +20,7 @@
Network *Network `json:"network"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Network, err
}
diff --git a/openstack/networking/v2/ports/requests.go b/openstack/networking/v2/ports/requests.go
index c846de9..78aebae 100644
--- a/openstack/networking/v2/ports/requests.go
+++ b/openstack/networking/v2/ports/requests.go
@@ -73,8 +73,8 @@
url += query
}
- return pagination.NewPager(c, url, func(r pagination.LastHTTPResponse) pagination.Page {
- return PortPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
+ return PortPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -83,7 +83,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", getURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -162,7 +162,7 @@
_, res.Err = perigee.Request("POST", createURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
DumpReqJson: true,
})
@@ -228,7 +228,7 @@
_, res.Err = perigee.Request("PUT", updateURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200, 201},
})
return res
diff --git a/openstack/networking/v2/ports/results.go b/openstack/networking/v2/ports/results.go
index cedd658..6681123 100644
--- a/openstack/networking/v2/ports/results.go
+++ b/openstack/networking/v2/ports/results.go
@@ -7,7 +7,7 @@
)
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a port resource.
@@ -20,7 +20,7 @@
Port *Port `json:"port"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Port, err
}
diff --git a/openstack/networking/v2/subnets/requests.go b/openstack/networking/v2/subnets/requests.go
index 8eed269..17c5b82 100644
--- a/openstack/networking/v2/subnets/requests.go
+++ b/openstack/networking/v2/subnets/requests.go
@@ -72,8 +72,8 @@
url += query
}
- return pagination.NewPager(c, url, func(r pagination.LastHTTPResponse) pagination.Page {
- return SubnetPage{pagination.LinkedPageBase{LastHTTPResponse: r}}
+ return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
+ return SubnetPage{pagination.LinkedPageBase{PageResult: r}}
})
}
@@ -82,7 +82,7 @@
var res GetResult
_, res.Err = perigee.Request("GET", getURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200},
})
return res
@@ -177,7 +177,7 @@
_, res.Err = perigee.Request("POST", createURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{201},
})
@@ -236,7 +236,7 @@
_, res.Err = perigee.Request("PUT", updateURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res.Resp,
+ Results: &res.Body,
OkCodes: []int{200, 201},
})
diff --git a/openstack/networking/v2/subnets/results.go b/openstack/networking/v2/subnets/results.go
index 3c9ef71..c87504c 100644
--- a/openstack/networking/v2/subnets/results.go
+++ b/openstack/networking/v2/subnets/results.go
@@ -7,7 +7,7 @@
)
type commonResult struct {
- gophercloud.CommonResult
+ gophercloud.Result
}
// Extract is a function that accepts a result and extracts a subnet resource.
@@ -20,7 +20,7 @@
Subnet *Subnet `json:"subnet"`
}
- err := mapstructure.Decode(r.Resp, &res)
+ err := mapstructure.Decode(r.Body, &res)
return res.Subnet, err
}
diff --git a/openstack/objectstorage/v1/accounts/requests.go b/openstack/objectstorage/v1/accounts/requests.go
index 55fcb05..a364bcc 100644
--- a/openstack/objectstorage/v1/accounts/requests.go
+++ b/openstack/objectstorage/v1/accounts/requests.go
@@ -46,7 +46,7 @@
MoreHeaders: h,
OkCodes: []int{204},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
@@ -80,8 +80,7 @@
}
// Update is a function that creates, updates, or deletes an account's metadata.
-// To extract the headers returned, call the ExtractHeaders method on the
-// UpdateResult.
+// To extract the headers returned, call the Extract method on the UpdateResult.
func Update(c *gophercloud.ServiceClient, opts UpdateOptsBuilder) UpdateResult {
var res UpdateResult
h := c.Provider.AuthenticatedHeaders()
@@ -101,7 +100,7 @@
MoreHeaders: h,
OkCodes: []int{204},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
diff --git a/openstack/objectstorage/v1/accounts/requests_test.go b/openstack/objectstorage/v1/accounts/requests_test.go
index 0090eea..d109214 100644
--- a/openstack/objectstorage/v1/accounts/requests_test.go
+++ b/openstack/objectstorage/v1/accounts/requests_test.go
@@ -27,10 +27,8 @@
})
options := &UpdateOpts{Metadata: map[string]string{"gophercloud-test": "accounts"}}
- _, err := Update(fake.ServiceClient(), options).ExtractHeaders()
- if err != nil {
- t.Fatalf("Unable to update account: %v", err)
- }
+ _, err := Update(fake.ServiceClient(), options).Extract()
+ th.AssertNoErr(t, err)
}
func TestGetAccount(t *testing.T) {
diff --git a/openstack/objectstorage/v1/accounts/results.go b/openstack/objectstorage/v1/accounts/results.go
index 8ff8183..e42577a 100644
--- a/openstack/objectstorage/v1/accounts/results.go
+++ b/openstack/objectstorage/v1/accounts/results.go
@@ -1,14 +1,15 @@
package accounts
import (
+ "net/http"
"strings"
- objectstorage "github.com/rackspace/gophercloud/openstack/objectstorage/v1"
+ "github.com/rackspace/gophercloud"
)
-// GetResult is returned from a call to the Get function. See v1.CommonResult.
+// GetResult is returned from a call to the Get function.
type GetResult struct {
- objectstorage.CommonResult
+ gophercloud.Result
}
// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
@@ -19,7 +20,7 @@
}
metadata := make(map[string]string)
- for k, v := range gr.Resp.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]
@@ -28,7 +29,13 @@
return metadata, nil
}
-// UpdateResult is returned from a call to the Update function. See v1.CommonResult.
+// UpdateResult is returned from a call to the Update function.
type UpdateResult struct {
- objectstorage.CommonResult
+ gophercloud.Result
+}
+
+// Extract returns the unmodified HTTP headers and any error conditions encountered during the
+// metadata update.
+func (ur UpdateResult) Extract() (http.Header, error) {
+ return ur.Header, ur.Err
}
diff --git a/openstack/objectstorage/v1/common.go b/openstack/objectstorage/v1/common.go
deleted file mode 100644
index 1a6c44a..0000000
--- a/openstack/objectstorage/v1/common.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package v1
-
-import (
- "net/http"
-)
-
-// CommonResult is a structure that contains the response and error of a call to an
-// object storage endpoint.
-type CommonResult struct {
- Resp *http.Response
- Err error
-}
-
-// ExtractHeaders will extract and return the headers from a *http.Response.
-func (cr CommonResult) ExtractHeaders() (http.Header, error) {
- if cr.Err != nil {
- return nil, cr.Err
- }
-
- var headers http.Header
- if cr.Err != nil {
- return headers, cr.Err
- }
- return cr.Resp.Header, nil
-}
diff --git a/openstack/objectstorage/v1/containers/requests.go b/openstack/objectstorage/v1/containers/requests.go
index ce3f540..25b68fd 100644
--- a/openstack/objectstorage/v1/containers/requests.go
+++ b/openstack/objectstorage/v1/containers/requests.go
@@ -52,8 +52,8 @@
}
}
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- p := ContainerPage{pagination.MarkerPageBase{LastHTTPResponse: r}}
+ createPage := func(r pagination.PageResult) pagination.Page {
+ p := ContainerPage{pagination.MarkerPageBase{PageResult: r}}
p.MarkerPageBase.Owner = p
return p
}
@@ -115,7 +115,7 @@
MoreHeaders: h,
OkCodes: []int{201, 204},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
@@ -127,7 +127,7 @@
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{204},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
@@ -186,7 +186,7 @@
MoreHeaders: h,
OkCodes: []int{204},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
@@ -200,7 +200,7 @@
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{204},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
diff --git a/openstack/objectstorage/v1/containers/requests_test.go b/openstack/objectstorage/v1/containers/requests_test.go
index 9562676..a134272 100644
--- a/openstack/objectstorage/v1/containers/requests_test.go
+++ b/openstack/objectstorage/v1/containers/requests_test.go
@@ -136,7 +136,7 @@
})
options := CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}}
- headers, err := Create(fake.ServiceClient(), "testContainer", options).ExtractHeaders()
+ headers, err := Create(fake.ServiceClient(), "testContainer", options).Extract()
if err != nil {
t.Fatalf("Unexpected error creating container: %v", err)
}
@@ -154,7 +154,7 @@
w.WriteHeader(http.StatusNoContent)
})
- _, err := Delete(fake.ServiceClient(), "testContainer").ExtractHeaders()
+ _, err := Delete(fake.ServiceClient(), "testContainer").Extract()
if err != nil {
t.Fatalf("Unexpected error deleting container: %v", err)
}
@@ -172,7 +172,7 @@
})
options := &UpdateOpts{Metadata: map[string]string{"foo": "bar"}}
- _, err := Update(fake.ServiceClient(), "testContainer", options).ExtractHeaders()
+ _, err := Update(fake.ServiceClient(), "testContainer", options).Extract()
if err != nil {
t.Fatalf("Unexpected error updating container metadata: %v", err)
}
diff --git a/openstack/objectstorage/v1/containers/results.go b/openstack/objectstorage/v1/containers/results.go
index 227a9dc..780d4ae 100644
--- a/openstack/objectstorage/v1/containers/results.go
+++ b/openstack/objectstorage/v1/containers/results.go
@@ -2,9 +2,10 @@
import (
"fmt"
+ "net/http"
"strings"
- objectstorage "github.com/rackspace/gophercloud/openstack/objectstorage/v1"
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
"github.com/mitchellh/mapstructure"
@@ -98,7 +99,7 @@
// GetResult represents the result of a get operation.
type GetResult struct {
- objectstorage.CommonResult
+ gophercloud.Result
}
// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
@@ -108,7 +109,7 @@
return nil, gr.Err
}
metadata := make(map[string]string)
- for k, v := range gr.Resp.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]
@@ -117,23 +118,32 @@
return metadata, nil
}
+type headerResult struct {
+ gophercloud.Result
+}
+
+// Extract pulls the unmodified headers from a Create, Update, or Delete result.
+func (result headerResult) Extract() (http.Header, error) {
+ return result.Header, result.Err
+}
+
// CreateResult represents the result of a create operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeaders'
// method on the result struct.
type CreateResult struct {
- objectstorage.CommonResult
+ headerResult
}
// UpdateResult represents the result of an update operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeaders'
// method on the result struct.
type UpdateResult struct {
- objectstorage.CommonResult
+ headerResult
}
// DeleteResult represents the result of a delete operation. To extract the
// the headers from the HTTP response, you can invoke the 'ExtractHeaders'
// method on the result struct.
type DeleteResult struct {
- objectstorage.CommonResult
+ headerResult
}
diff --git a/openstack/objectstorage/v1/objects/requests.go b/openstack/objectstorage/v1/objects/requests.go
index 3274e04..13d94f8 100644
--- a/openstack/objectstorage/v1/objects/requests.go
+++ b/openstack/objectstorage/v1/objects/requests.go
@@ -3,6 +3,7 @@
import (
"fmt"
"io"
+ "io/ioutil"
"time"
"github.com/racker/perigee"
@@ -58,8 +59,8 @@
}
}
- createPage := func(r pagination.LastHTTPResponse) pagination.Page {
- p := ObjectPage{pagination.MarkerPageBase{LastHTTPResponse: r}}
+ createPage := func(r pagination.PageResult) pagination.Page {
+ p := ObjectPage{pagination.MarkerPageBase{PageResult: r}}
p.MarkerPageBase.Owner = p
return p
}
@@ -128,8 +129,11 @@
MoreHeaders: h,
OkCodes: []int{200},
})
+ defer resp.HttpResponse.Body.Close()
+ body, err := ioutil.ReadAll(resp.HttpResponse.Body)
+ res.Body = body
res.Err = err
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
return res
}
@@ -214,7 +218,7 @@
MoreHeaders: h,
OkCodes: []int{201},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
@@ -270,7 +274,7 @@
MoreHeaders: h,
OkCodes: []int{201},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
return res
}
@@ -312,7 +316,7 @@
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{204},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
@@ -357,8 +361,8 @@
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{200, 204},
})
+ res.Header = resp.HttpResponse.Header
res.Err = err
- res.Resp = &resp.HttpResponse
return res
}
@@ -414,7 +418,7 @@
MoreHeaders: h,
OkCodes: []int{202},
})
- res.Resp = &resp.HttpResponse
+ res.Header = resp.HttpResponse.Header
res.Err = err
return res
}
diff --git a/openstack/objectstorage/v1/objects/requests_test.go b/openstack/objectstorage/v1/objects/requests_test.go
index 11d7c44..7147782 100644
--- a/openstack/objectstorage/v1/objects/requests_test.go
+++ b/openstack/objectstorage/v1/objects/requests_test.go
@@ -167,7 +167,7 @@
content := bytes.NewBufferString("Did gyre and gimble in the wabe")
options := &CreateOpts{ContentType: "application/json"}
- _, err := Create(fake.ServiceClient(), "testContainer", "testObject", content, options).ExtractHeaders()
+ _, err := Create(fake.ServiceClient(), "testContainer", "testObject", content, options).Extract()
if err != nil {
t.Fatalf("Unexpected error creating object: %v", err)
}
@@ -186,7 +186,7 @@
})
options := &CopyOpts{Destination: "/newTestContainer/newTestObject"}
- _, err := Copy(fake.ServiceClient(), "testContainer", "testObject", options).ExtractHeaders()
+ _, err := Copy(fake.ServiceClient(), "testContainer", "testObject", options).Extract()
if err != nil {
t.Fatalf("Unexpected error copying object: %v", err)
}
@@ -203,7 +203,7 @@
w.WriteHeader(http.StatusNoContent)
})
- _, err := Delete(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractHeaders()
+ _, err := Delete(fake.ServiceClient(), "testContainer", "testObject", nil).Extract()
if err != nil {
t.Fatalf("Unexpected error deleting object: %v", err)
}
@@ -221,7 +221,7 @@
w.WriteHeader(http.StatusAccepted)
})
- _, err := Update(fake.ServiceClient(), "testContainer", "testObject", &UpdateOpts{Metadata: metadata}).ExtractHeaders()
+ _, err := Update(fake.ServiceClient(), "testContainer", "testObject", &UpdateOpts{Metadata: metadata}).Extract()
if err != nil {
t.Fatalf("Unexpected error updating object metadata: %v", err)
}
diff --git a/openstack/objectstorage/v1/objects/results.go b/openstack/objectstorage/v1/objects/results.go
index 1dda7a3..e662b69 100644
--- a/openstack/objectstorage/v1/objects/results.go
+++ b/openstack/objectstorage/v1/objects/results.go
@@ -2,10 +2,10 @@
import (
"fmt"
- "io/ioutil"
+ "net/http"
"strings"
- objectstorage "github.com/rackspace/gophercloud/openstack/objectstorage/v1"
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
"github.com/mitchellh/mapstructure"
@@ -98,27 +98,21 @@
// DownloadResult is a *http.Response that is returned from a call to the Download function.
type DownloadResult struct {
- objectstorage.CommonResult
+ gophercloud.Result
}
// ExtractContent is a function that takes a DownloadResult (of type *http.Response)
// and returns the object's content.
func (dr DownloadResult) ExtractContent() ([]byte, error) {
if dr.Err != nil {
- return nil, nil
+ return nil, dr.Err
}
- var body []byte
- defer dr.Resp.Body.Close()
- body, err := ioutil.ReadAll(dr.Resp.Body)
- if err != nil {
- return body, fmt.Errorf("Error trying to read DownloadResult body: %v", err)
- }
- return body, nil
+ return dr.Body.([]byte), nil
}
// GetResult is a *http.Response that is returned from a call to the Get function.
type GetResult struct {
- objectstorage.CommonResult
+ gophercloud.Result
}
// ExtractMetadata is a function that takes a GetResult (of type *http.Response)
@@ -128,7 +122,7 @@
return nil, gr.Err
}
metadata := make(map[string]string)
- for k, v := range gr.Resp.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]
@@ -137,22 +131,32 @@
return metadata, nil
}
+type headerResult struct {
+ gophercloud.Result
+}
+
+// Extract returns the unmodified HTTP response headers from a Create, Update, or Delete call, as
+// well as any errors that occurred during the call.
+func (result headerResult) Extract() (http.Header, error) {
+ return result.Header, result.Err
+}
+
// CreateResult represents the result of a create operation.
type CreateResult struct {
- objectstorage.CommonResult
+ headerResult
}
// UpdateResult represents the result of an update operation.
type UpdateResult struct {
- objectstorage.CommonResult
+ headerResult
}
// DeleteResult represents the result of a delete operation.
type DeleteResult struct {
- objectstorage.CommonResult
+ headerResult
}
// CopyResult represents the result of a copy operation.
type CopyResult struct {
- objectstorage.CommonResult
+ headerResult
}
diff --git a/pagination/http.go b/pagination/http.go
index dd2c2d7..ba2c615 100644
--- a/pagination/http.go
+++ b/pagination/http.go
@@ -11,39 +11,38 @@
"github.com/rackspace/gophercloud"
)
-// LastHTTPResponse stores generic information derived from an HTTP response.
-// This exists primarily because the body of an http.Response can only be used once.
-type LastHTTPResponse struct {
+// PageResult stores the HTTP response that returned the current page of results.
+type PageResult struct {
+ gophercloud.Result
url.URL
- http.Header
- Body interface{}
}
-// RememberHTTPResponse parses an HTTP response as JSON and returns a LastHTTPResponse containing the results.
-// The main reason to do this instead of holding the response directly is that a response body can only be read once.
-// Also, this centralizes the JSON decoding.
-func RememberHTTPResponse(resp http.Response) (LastHTTPResponse, error) {
+// PageResultFrom parses an HTTP response as JSON and returns a PageResult containing the
+// results, interpreting it as JSON if the content type indicates.
+func PageResultFrom(resp http.Response) (PageResult, error) {
var parsedBody interface{}
defer resp.Body.Close()
rawBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
- return LastHTTPResponse{}, err
+ return PageResult{}, err
}
if strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
err = json.Unmarshal(rawBody, &parsedBody)
if err != nil {
- return LastHTTPResponse{}, err
+ return PageResult{}, err
}
} else {
parsedBody = rawBody
}
- return LastHTTPResponse{
- URL: *resp.Request.URL,
- Header: resp.Header,
- Body: parsedBody,
+ return PageResult{
+ Result: gophercloud.Result{
+ Body: parsedBody,
+ Header: resp.Header,
+ },
+ URL: *resp.Request.URL,
}, err
}
diff --git a/pagination/linked.go b/pagination/linked.go
index 0376edb..447d4b1 100644
--- a/pagination/linked.go
+++ b/pagination/linked.go
@@ -4,7 +4,7 @@
// LinkedPageBase may be embedded to implement a page that provides navigational "Next" and "Previous" links within its result.
type LinkedPageBase struct {
- LastHTTPResponse
+ PageResult
// LinkPath lists the keys that should be traversed within a response to arrive at the "next" pointer.
// If any link along the path is missing, an empty URL will be returned.
diff --git a/pagination/linked_test.go b/pagination/linked_test.go
index 2621f98..4d3248e 100644
--- a/pagination/linked_test.go
+++ b/pagination/linked_test.go
@@ -57,8 +57,8 @@
client := createClient()
- createPage := func(r LastHTTPResponse) Page {
- return LinkedPageResult{LinkedPageBase{LastHTTPResponse: r}}
+ createPage := func(r PageResult) Page {
+ return LinkedPageResult{LinkedPageBase{PageResult: r}}
}
return NewPager(client, testhelper.Server.URL+"/page1", createPage)
diff --git a/pagination/marker.go b/pagination/marker.go
index 41b493a..e7688c2 100644
--- a/pagination/marker.go
+++ b/pagination/marker.go
@@ -11,7 +11,7 @@
// MarkerPageBase is a page in a collection that's paginated by "limit" and "marker" query parameters.
type MarkerPageBase struct {
- LastHTTPResponse
+ PageResult
// Owner is a reference to the embedding struct.
Owner MarkerPage
diff --git a/pagination/marker_test.go b/pagination/marker_test.go
index e30264c..3b1df1d 100644
--- a/pagination/marker_test.go
+++ b/pagination/marker_test.go
@@ -56,8 +56,8 @@
client := createClient()
- createPage := func(r LastHTTPResponse) Page {
- p := MarkerPageResult{MarkerPageBase{LastHTTPResponse: r}}
+ createPage := func(r PageResult) Page {
+ p := MarkerPageResult{MarkerPageBase{PageResult: r}}
p.MarkerPageBase.Owner = p
return p
}
diff --git a/pagination/pager.go b/pagination/pager.go
index 75fe408..5c20e16 100644
--- a/pagination/pager.go
+++ b/pagination/pager.go
@@ -33,7 +33,7 @@
initialURL string
- createPage func(r LastHTTPResponse) Page
+ createPage func(r PageResult) Page
Err error
@@ -43,7 +43,7 @@
// NewPager constructs a manually-configured pager.
// Supply the URL for the first page, a function that requests a specific page given a URL, and a function that counts a page.
-func NewPager(client *gophercloud.ServiceClient, initialURL string, createPage func(r LastHTTPResponse) Page) Pager {
+func NewPager(client *gophercloud.ServiceClient, initialURL string, createPage func(r PageResult) Page) Pager {
return Pager{
client: client,
initialURL: initialURL,
@@ -53,7 +53,7 @@
// WithPageCreator returns a new Pager that substitutes a different page creation function. This is
// useful for overriding List functions in delegation.
-func (p Pager) WithPageCreator(createPage func(r LastHTTPResponse) Page) Pager {
+func (p Pager) WithPageCreator(createPage func(r PageResult) Page) Pager {
return Pager{
client: p.client,
initialURL: p.initialURL,
@@ -67,7 +67,7 @@
return nil, err
}
- remembered, err := RememberHTTPResponse(resp)
+ remembered, err := PageResultFrom(resp)
if err != nil {
return nil, err
}
diff --git a/pagination/single.go b/pagination/single.go
index a7f6fde..4dd3c5c 100644
--- a/pagination/single.go
+++ b/pagination/single.go
@@ -1,7 +1,7 @@
package pagination
// SinglePageBase may be embedded in a Page that contains all of the results from an operation at once.
-type SinglePageBase LastHTTPResponse
+type SinglePageBase PageResult
// NextPageURL always returns "" to indicate that there are no more pages to return.
func (current SinglePageBase) NextPageURL() (string, error) {
diff --git a/pagination/single_test.go b/pagination/single_test.go
index 31003e5..8817d57 100644
--- a/pagination/single_test.go
+++ b/pagination/single_test.go
@@ -45,7 +45,7 @@
fmt.Fprintf(w, `{ "ints": [1, 2, 3] }`)
})
- createPage := func(r LastHTTPResponse) Page {
+ createPage := func(r PageResult) Page {
return SinglePageResult{SinglePageBase(r)}
}
diff --git a/results.go b/results.go
index 647ba46..f60bc76 100644
--- a/results.go
+++ b/results.go
@@ -1,11 +1,19 @@
package gophercloud
-// CommonResult acts as a base struct that other results can embed. It contains
-// the deserialized JSON structure returned from the server (Resp), and any
-// errors that might have occurred during transport or deserialization.
-type CommonResult struct {
- Resp map[string]interface{}
- Err error
+import "net/http"
+
+// Result acts as a base struct that other results can embed.
+type Result struct {
+ // Body is the payload of the HTTP response from the server. In most cases, this will be the
+ // deserialized JSON structure.
+ Body interface{}
+
+ // Header contains the HTTP header structure from the original response.
+ Header http.Header
+
+ // Err is an error that occurred during the operation. It's deferred until extraction to make
+ // it easier to chain operations.
+ Err error
}
// RFC3339Milli describes a time format used by API responses.