remove mapstructure from identity,networking,objectstorage,orchestration,pagination
diff --git a/openstack/identity/v3/endpoints/results.go b/openstack/identity/v3/endpoints/results.go
index 7c20b8c..09e58e5 100644
--- a/openstack/identity/v3/endpoints/results.go
+++ b/openstack/identity/v3/endpoints/results.go
@@ -1,7 +1,6 @@
package endpoints
import (
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -13,17 +12,11 @@
// Extract interprets a GetResult, CreateResult or UpdateResult as a concrete Endpoint.
// An error is returned if the original call or the extraction failed.
func (r commonResult) Extract() (*Endpoint, error) {
- if r.Err != nil {
- return nil, r.Err
+ var s struct {
+ Endpoint *Endpoint `json:"endpoint"`
}
-
- var res struct {
- Endpoint `json:"endpoint"`
- }
-
- err := mapstructure.Decode(r.Body, &res)
-
- return &res.Endpoint, err
+ err := r.ExtractInto(&s)
+ return s.Endpoint, err
}
// CreateResult is the deferred result of a Create call.
@@ -48,12 +41,12 @@
// Endpoint describes the entry point for another service's API.
type Endpoint struct {
- ID string `mapstructure:"id" json:"id"`
- Availability gophercloud.Availability `mapstructure:"interface" json:"interface"`
- Name string `mapstructure:"name" json:"name"`
- Region string `mapstructure:"region" json:"region"`
- ServiceID string `mapstructure:"service_id" json:"service_id"`
- URL string `mapstructure:"url" json:"url"`
+ ID string `json:"id"`
+ Availability gophercloud.Availability `json:"interface"`
+ Name string `json:"name"`
+ Region string `json:"region"`
+ ServiceID string `json:"service_id"`
+ URL string `json:"url"`
}
// EndpointPage is a single page of Endpoint results.
@@ -64,19 +57,15 @@
// IsEmpty returns true if no Endpoints were returned.
func (p EndpointPage) IsEmpty() (bool, error) {
es, err := ExtractEndpoints(p)
- if err != nil {
- return true, err
- }
- return len(es) == 0, nil
+ return len(es) == 0, err
}
// ExtractEndpoints extracts an Endpoint slice from a Page.
func ExtractEndpoints(page pagination.Page) ([]Endpoint, error) {
- var response struct {
- Endpoints []Endpoint `mapstructure:"endpoints"`
+ r := page.(EndpointPage)
+ var s struct {
+ Endpoints []Endpoint `json:"endpoints"`
}
-
- err := mapstructure.Decode(page.(EndpointPage).Body, &response)
-
- return response.Endpoints, err
+ err := r.ExtractInto(&s)
+ return s.Endpoints, err
}
diff --git a/openstack/identity/v3/roles/results.go b/openstack/identity/v3/roles/results.go
index 75549d3..86f21a0 100644
--- a/openstack/identity/v3/roles/results.go
+++ b/openstack/identity/v3/roles/results.go
@@ -1,10 +1,6 @@
package roles
-import (
- "github.com/gophercloud/gophercloud/pagination"
-
- "github.com/mitchellh/mapstructure"
-)
+import "github.com/gophercloud/gophercloud/pagination"
// RoleAssignment is the result of a role assignments query.
type RoleAssignment struct {
@@ -20,7 +16,7 @@
type Scope struct {
Domain Domain `json:"domain,omitempty"`
- Project Project `json:"domain,omitempty"`
+ Project Project `json:"project,omitempty"`
}
type Domain struct {
@@ -47,35 +43,26 @@
// IsEmpty returns true if the page contains no results.
func (p RoleAssignmentsPage) IsEmpty() (bool, error) {
roleAssignments, err := ExtractRoleAssignments(p)
- if err != nil {
- return true, err
- }
- return len(roleAssignments) == 0, nil
+ return len(roleAssignments) == 0, err
}
// NextPageURL uses the response's embedded link reference to navigate to the next page of results.
func (page RoleAssignmentsPage) NextPageURL() (string, error) {
- type resp struct {
+ var s struct {
Links struct {
- Next string `mapstructure:"next"`
- } `mapstructure:"links"`
+ Next string `json:"next"`
+ } `json:"links"`
}
-
- var r resp
- err := mapstructure.Decode(page.Body, &r)
- if err != nil {
- return "", err
- }
-
- return r.Links.Next, nil
+ err := page.ExtractInto(&s)
+ return s.Links.Next, err
}
// ExtractRoleAssignments extracts a slice of RoleAssignments from a Collection acquired from List.
func ExtractRoleAssignments(page pagination.Page) ([]RoleAssignment, error) {
- var response struct {
- RoleAssignments []RoleAssignment `mapstructure:"role_assignments"`
+ r := page.(RoleAssignmentsPage)
+ var s struct {
+ RoleAssignments []RoleAssignment `json:"role_assignments"`
}
-
- err := mapstructure.Decode(page.(RoleAssignmentsPage).Body, &response)
- return response.RoleAssignments, err
+ err := r.ExtractInto(&s)
+ return s.RoleAssignments, err
}
diff --git a/openstack/identity/v3/services/results.go b/openstack/identity/v3/services/results.go
index c55ee62..45040c6 100644
--- a/openstack/identity/v3/services/results.go
+++ b/openstack/identity/v3/services/results.go
@@ -3,8 +3,6 @@
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
-
- "github.com/mitchellh/mapstructure"
)
type commonResult struct {
@@ -14,17 +12,11 @@
// Extract interprets a GetResult, CreateResult or UpdateResult as a concrete Service.
// An error is returned if the original call or the extraction failed.
func (r commonResult) Extract() (*Service, error) {
- if r.Err != nil {
- return nil, r.Err
+ var s struct {
+ Service *Service `json:"service"`
}
-
- var res struct {
- Service `json:"service"`
- }
-
- err := mapstructure.Decode(r.Body, &res)
-
- return &res.Service, err
+ err := r.ExtractInto(&s)
+ return s.Service, err
}
// CreateResult is the deferred result of a Create call.
@@ -63,18 +55,15 @@
// IsEmpty returns true if the page contains no results.
func (p ServicePage) IsEmpty() (bool, error) {
services, err := ExtractServices(p)
- if err != nil {
- return true, err
- }
- return len(services) == 0, nil
+ return len(services) == 0, err
}
// ExtractServices extracts a slice of Services from a Collection acquired from List.
func ExtractServices(page pagination.Page) ([]Service, error) {
- var response struct {
- Services []Service `mapstructure:"services"`
+ r := page.(ServicePage)
+ var s struct {
+ Services []Service `json:"services"`
}
-
- err := mapstructure.Decode(page.(ServicePage).Body, &response)
- return response.Services, err
+ err := r.ExtractInto(&s)
+ return s.Services, err
}
diff --git a/openstack/identity/v3/tokens/results.go b/openstack/identity/v3/tokens/results.go
index ec98c1c..7dd2c0b 100644
--- a/openstack/identity/v3/tokens/results.go
+++ b/openstack/identity/v3/tokens/results.go
@@ -3,7 +3,6 @@
import (
"time"
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
)
@@ -12,10 +11,10 @@
// If supported, it contains a region specifier, again if provided.
// The significance of the Region field will depend upon your provider.
type Endpoint struct {
- ID string `mapstructure:"id"`
- Region string `mapstructure:"region"`
- Interface string `mapstructure:"interface"`
- URL string `mapstructure:"url"`
+ ID string `json:"id"`
+ Region string `json:"region"`
+ Interface string `json:"interface"`
+ URL string `json:"url"`
}
// CatalogEntry provides a type-safe interface to an Identity API V3 service catalog listing.
@@ -27,18 +26,18 @@
type CatalogEntry struct {
// Service ID
- ID string `mapstructure:"id"`
+ ID string `json:"id"`
// Name will contain the provider-specified name for the service.
- Name string `mapstructure:"name"`
+ Name string `json:"name"`
// Type will contain a type string if OpenStack defines a type for the service.
// Otherwise, for provider-specific services, the provider may assign their own type strings.
- Type string `mapstructure:"type"`
+ Type string `json:"type"`
// Endpoints will let the caller iterate over all the different endpoints that may exist for
// the service.
- Endpoints []Endpoint `mapstructure:"endpoints"`
+ Endpoints []Endpoint `json:"endpoints"`
}
// ServiceCatalog provides a view into the service catalog from a previous, successful authentication.
@@ -59,14 +58,10 @@
// ExtractToken interprets a commonResult as a Token.
func (r commonResult) ExtractToken() (*Token, error) {
- if r.Err != nil {
- return nil, r.Err
- }
-
- var response struct {
+ var s struct {
Token struct {
- ExpiresAt string `mapstructure:"expires_at"`
- } `mapstructure:"token"`
+ ExpiresAt string `json:"expires_at"`
+ } `json:"token"`
}
var token Token
@@ -74,35 +69,26 @@
// Parse the token itself from the stored headers.
token.ID = r.Header.Get("X-Subject-Token")
- err := mapstructure.Decode(r.Body, &response)
+ err := r.ExtractInto(&s)
if err != nil {
return nil, err
}
// Attempt to parse the timestamp.
- token.ExpiresAt, err = time.Parse(gophercloud.RFC3339Milli, response.Token.ExpiresAt)
+ token.ExpiresAt, err = time.Parse(gophercloud.RFC3339Milli, s.Token.ExpiresAt)
return &token, err
}
// ExtractServiceCatalog returns the ServiceCatalog that was generated along with the user's Token.
-func (result CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error) {
- if result.Err != nil {
- return nil, result.Err
- }
-
- var response struct {
+func (r CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error) {
+ var s struct {
Token struct {
- Entries []CatalogEntry `mapstructure:"catalog"`
- } `mapstructure:"token"`
+ Entries []CatalogEntry `json:"catalog"`
+ } `json:"token"`
}
-
- err := mapstructure.Decode(result.Body, &response)
- if err != nil {
- return nil, err
- }
-
- return &ServiceCatalog{Entries: response.Token.Entries}, nil
+ err := r.ExtractInto(&s)
+ return &ServiceCatalog{Entries: s.Token.Entries}, err
}
// CreateResult defers the interpretation of a created token.