remove mapstructure from identity,networking,objectstorage,orchestration,pagination
diff --git a/openstack/identity/v2/extensions/admin/roles/results.go b/openstack/identity/v2/extensions/admin/roles/results.go
index 6cfe3ac..608f206 100644
--- a/openstack/identity/v2/extensions/admin/roles/results.go
+++ b/openstack/identity/v2/extensions/admin/roles/results.go
@@ -1,7 +1,6 @@
package roles
import (
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -29,21 +28,17 @@
// IsEmpty determines whether or not a page of Tenants contains any results.
func (page RolePage) IsEmpty() (bool, error) {
users, err := ExtractRoles(page)
- if err != nil {
- return false, err
- }
- return len(users) == 0, nil
+ return len(users) == 0, err
}
// ExtractRoles returns a slice of roles contained in a single page of results.
func ExtractRoles(page pagination.Page) ([]Role, error) {
- casted := page.(RolePage).Body
- var response struct {
- Roles []Role `mapstructure:"roles"`
+ r := page.(RolePage)
+ var s struct {
+ Roles []Role `json:"roles"`
}
-
- err := mapstructure.Decode(casted, &response)
- return response.Roles, err
+ err := r.ExtractInto(&s)
+ return s.Roles, err
}
// UserRoleResult represents the result of either an AddUserRole or
diff --git a/openstack/identity/v2/extensions/delegate.go b/openstack/identity/v2/extensions/delegate.go
index e6af80e..4b2c6a7 100644
--- a/openstack/identity/v2/extensions/delegate.go
+++ b/openstack/identity/v2/extensions/delegate.go
@@ -1,7 +1,6 @@
package extensions
import (
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
common "github.com/gophercloud/gophercloud/openstack/common/extensions"
"github.com/gophercloud/gophercloud/pagination"
@@ -24,16 +23,15 @@
// ExtractExtensions accepts a Page struct, specifically an ExtensionPage struct, and extracts the
// elements into a slice of Extension structs.
func ExtractExtensions(page pagination.Page) ([]common.Extension, error) {
+ r := page.(ExtensionPage)
// Identity v2 adds an intermediate "values" object.
-
- var resp struct {
+ var s struct {
Extensions struct {
- Values []common.Extension `mapstructure:"values"`
- } `mapstructure:"extensions"`
+ Values []common.Extension `json:"values"`
+ } `json:"extensions"`
}
-
- err := mapstructure.Decode(page.(ExtensionPage).Body, &resp)
- return resp.Extensions.Values, err
+ err := r.ExtractInto(&s)
+ return s.Extensions.Values, err
}
// Get retrieves information for a specific extension using its alias.
diff --git a/openstack/identity/v2/tenants/results.go b/openstack/identity/v2/tenants/results.go
index cee7568..bf52554 100644
--- a/openstack/identity/v2/tenants/results.go
+++ b/openstack/identity/v2/tenants/results.go
@@ -1,7 +1,6 @@
package tenants
import (
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -9,16 +8,16 @@
// Tenant is a grouping of users in the identity service.
type Tenant struct {
// ID is a unique identifier for this tenant.
- ID string `mapstructure:"id"`
+ ID string `json:"id"`
// Name is a friendlier user-facing name for this tenant.
- Name string `mapstructure:"name"`
+ Name string `json:"name"`
// Description is a human-readable explanation of this Tenant's purpose.
- Description string `mapstructure:"description"`
+ Description string `json:"description"`
// Enabled indicates whether or not a tenant is active.
- Enabled bool `mapstructure:"enabled"`
+ Enabled bool `json:"enabled"`
}
// TenantPage is a single page of Tenant results.
@@ -29,34 +28,27 @@
// IsEmpty determines whether or not a page of Tenants contains any results.
func (page TenantPage) IsEmpty() (bool, error) {
tenants, err := ExtractTenants(page)
- if err != nil {
- return false, err
- }
- return len(tenants) == 0, nil
+ return len(tenants) == 0, err
}
// NextPageURL extracts the "next" link from the tenants_links section of the result.
func (page TenantPage) NextPageURL() (string, error) {
- type resp struct {
- Links []gophercloud.Link `mapstructure:"tenants_links"`
+ var s struct {
+ Links []gophercloud.Link `json:"tenants_links"`
}
-
- var r resp
- err := mapstructure.Decode(page.Body, &r)
+ err := page.ExtractInto(&s)
if err != nil {
return "", err
}
-
- return gophercloud.ExtractNextURL(r.Links)
+ return gophercloud.ExtractNextURL(s.Links)
}
// ExtractTenants returns a slice of Tenants contained in a single page of results.
func ExtractTenants(page pagination.Page) ([]Tenant, error) {
- casted := page.(TenantPage).Body
- var response struct {
- Tenants []Tenant `mapstructure:"tenants"`
+ r := page.(TenantPage)
+ var s struct {
+ Tenants []Tenant `json:"tenants"`
}
-
- err := mapstructure.Decode(casted, &response)
- return response.Tenants, err
+ err := r.ExtractInto(&s)
+ return s.Tenants, err
}
diff --git a/openstack/identity/v2/tokens/results.go b/openstack/identity/v2/tokens/results.go
index 9ef45b6..93c0554 100644
--- a/openstack/identity/v2/tokens/results.go
+++ b/openstack/identity/v2/tokens/results.go
@@ -3,7 +3,6 @@
import (
"time"
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
)
@@ -25,15 +24,17 @@
Tenant tenants.Tenant
}
-// Authorization need user info which can get from token authentication's response
+// Role is a role for a user.
type Role struct {
- Name string `mapstructure:"name"`
+ Name string `json:"name"`
}
+
+// User is an OpenStack user.
type User struct {
- ID string `mapstructure:"id"`
- Name string `mapstructure:"name"`
- UserName string `mapstructure:"username"`
- Roles []Role `mapstructure:"roles"`
+ ID string `json:"id"`
+ Name string `json:"name"`
+ UserName string `json:"username"`
+ Roles []Role `json:"roles"`
}
// Endpoint represents a single API endpoint offered by a service.
@@ -45,14 +46,14 @@
//
// In all cases, fields which aren't supported by the provider and service combined will assume a zero-value ("").
type Endpoint struct {
- TenantID string `mapstructure:"tenantId"`
- PublicURL string `mapstructure:"publicURL"`
- InternalURL string `mapstructure:"internalURL"`
- AdminURL string `mapstructure:"adminURL"`
- Region string `mapstructure:"region"`
- VersionID string `mapstructure:"versionId"`
- VersionInfo string `mapstructure:"versionInfo"`
- VersionList string `mapstructure:"versionList"`
+ TenantID string `json:"tenantId"`
+ PublicURL string `json:"publicURL"`
+ InternalURL string `json:"internalURL"`
+ AdminURL string `json:"adminURL"`
+ Region string `json:"region"`
+ VersionID string `json:"versionId"`
+ VersionInfo string `json:"versionInfo"`
+ VersionList string `json:"versionList"`
}
// CatalogEntry provides a type-safe interface to an Identity API V2 service catalog listing.
@@ -63,15 +64,15 @@
// Otherwise, you'll tie the representation of the service to a specific provider.
type CatalogEntry struct {
// 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.
@@ -92,56 +93,43 @@
}
// ExtractToken returns the just-created Token from a CreateResult.
-func (result CreateResult) ExtractToken() (*Token, error) {
- if result.Err != nil {
- return nil, result.Err
- }
-
- var response struct {
+func (r CreateResult) ExtractToken() (*Token, error) {
+ var s struct {
Access struct {
Token struct {
- Expires string `mapstructure:"expires"`
- ID string `mapstructure:"id"`
- Tenant tenants.Tenant `mapstructure:"tenant"`
- } `mapstructure:"token"`
- } `mapstructure:"access"`
+ Expires string `json:"expires"`
+ ID string `json:"id"`
+ Tenant tenants.Tenant `json:"tenant"`
+ } `json:"token"`
+ } `json:"access"`
}
- err := mapstructure.Decode(result.Body, &response)
+ err := r.ExtractInto(&s)
if err != nil {
return nil, err
}
- expiresTs, err := time.Parse(gophercloud.RFC3339Milli, response.Access.Token.Expires)
+ expiresTs, err := time.Parse(gophercloud.RFC3339Milli, s.Access.Token.Expires)
if err != nil {
return nil, err
}
return &Token{
- ID: response.Access.Token.ID,
+ ID: s.Access.Token.ID,
ExpiresAt: expiresTs,
- Tenant: response.Access.Token.Tenant,
+ Tenant: s.Access.Token.Tenant,
}, nil
}
// 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 {
Access struct {
- Entries []CatalogEntry `mapstructure:"serviceCatalog"`
- } `mapstructure:"access"`
+ Entries []CatalogEntry `json:"serviceCatalog"`
+ } `json:"access"`
}
-
- err := mapstructure.Decode(result.Body, &response)
- if err != nil {
- return nil, err
- }
-
- return &ServiceCatalog{Entries: response.Access.Entries}, nil
+ err := r.ExtractInto(&s)
+ return &ServiceCatalog{Entries: s.Access.Entries}, err
}
// createErr quickly packs an error in a CreateResult.
@@ -150,21 +138,12 @@
}
// ExtractUser returns the User from a GetResult.
-func (result GetResult) ExtractUser() (*User, error) {
- if result.Err != nil {
- return nil, result.Err
- }
-
- var response struct {
+func (r GetResult) ExtractUser() (*User, error) {
+ var s struct {
Access struct {
- User User `mapstructure:"user"`
- } `mapstructure:"access"`
+ User User `json:"user"`
+ } `json:"access"`
}
-
- err := mapstructure.Decode(result.Body, &response)
- if err != nil {
- return nil, err
- }
-
- return &response.Access.User, nil
+ err := r.ExtractInto(&s)
+ return &s.Access.User, err
}
diff --git a/openstack/identity/v2/users/results.go b/openstack/identity/v2/users/results.go
index 37ba1be..c353c61 100644
--- a/openstack/identity/v2/users/results.go
+++ b/openstack/identity/v2/users/results.go
@@ -1,8 +1,6 @@
package users
import (
- "github.com/mitchellh/mapstructure"
-
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -25,7 +23,7 @@
Email string
// The ID of the tenant to which this user belongs.
- TenantID string `mapstructure:"tenant_id"`
+ TenantID string `json:"tenant_id"`
}
// Role assigns specific responsibilities to users, allowing them to accomplish
@@ -51,41 +49,33 @@
// IsEmpty determines whether or not a page of Tenants contains any results.
func (page UserPage) IsEmpty() (bool, error) {
users, err := ExtractUsers(page)
- if err != nil {
- return false, err
- }
- return len(users) == 0, nil
+ return len(users) == 0, err
}
// ExtractUsers returns a slice of Tenants contained in a single page of results.
func ExtractUsers(page pagination.Page) ([]User, error) {
- casted := page.(UserPage).Body
- var response struct {
- Users []User `mapstructure:"users"`
+ r := page.(UserPage)
+ var s struct {
+ Users []User `json:"users"`
}
-
- err := mapstructure.Decode(casted, &response)
- return response.Users, err
+ err := r.ExtractInto(&s)
+ return s.Users, err
}
// IsEmpty determines whether or not a page of Tenants contains any results.
func (page RolePage) IsEmpty() (bool, error) {
users, err := ExtractRoles(page)
- if err != nil {
- return false, err
- }
- return len(users) == 0, nil
+ return len(users) == 0, err
}
// ExtractRoles returns a slice of Roles contained in a single page of results.
func ExtractRoles(page pagination.Page) ([]Role, error) {
- casted := page.(RolePage).Body
- var response struct {
- Roles []Role `mapstructure:"roles"`
+ r := page.(RolePage)
+ var s struct {
+ Roles []Role `json:"roles"`
}
-
- err := mapstructure.Decode(casted, &response)
- return response.Roles, err
+ err := r.ExtractInto(&s)
+ return s.Roles, err
}
type commonResult struct {
@@ -94,17 +84,11 @@
// Extract interprets any commonResult as a User, if possible.
func (r commonResult) Extract() (*User, error) {
- if r.Err != nil {
- return nil, r.Err
+ var s struct {
+ User *User `json:"user"`
}
-
- var response struct {
- User User `mapstructure:"user"`
- }
-
- err := mapstructure.Decode(r.Body, &response)
-
- return &response.User, err
+ err := r.ExtractInto(&s)
+ return s.User, err
}
// CreateResult represents the result of a Create operation