remove mapstructure from blockstorage,cdn,compute,db pkgs
diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go
index 46731ef..905b32c 100644
--- a/openstack/db/v1/instances/results.go
+++ b/openstack/db/v1/instances/results.go
@@ -1,11 +1,8 @@
package instances
import (
- "fmt"
- "reflect"
"time"
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/db/v1/datastores"
"github.com/gophercloud/gophercloud/openstack/db/v1/flavors"
@@ -24,10 +21,10 @@
// Instance represents a remote MySQL instance.
type Instance struct {
// Indicates the datetime that the instance was created
- Created time.Time `mapstructure:"-"`
+ Created time.Time `json:"created"`
// Indicates the most recent datetime that the instance was updated.
- Updated time.Time `mapstructure:"-"`
+ Updated time.Time `json:"updated"`
// Indicates the hardware flavor the instance uses.
Flavor flavors.Flavor
@@ -80,34 +77,11 @@
// Extract will extract an Instance from various result structs.
func (r commonResult) Extract() (*Instance, error) {
- if r.Err != nil {
- return nil, r.Err
+ var s struct {
+ Instance *Instance `json:"instance"`
}
-
- var response struct {
- Instance Instance `mapstructure:"instance"`
- }
-
- err := mapstructure.Decode(r.Body, &response)
- val := r.Body.(map[string]interface{})["instance"].(map[string]interface{})
-
- if t, ok := val["created"].(string); ok && t != "" {
- creationTime, err := time.Parse(time.RFC3339, t)
- if err != nil {
- return &response.Instance, err
- }
- response.Instance.Created = creationTime
- }
-
- if t, ok := val["updated"].(string); ok && t != "" {
- updatedTime, err := time.Parse(time.RFC3339, t)
- if err != nil {
- return &response.Instance, err
- }
- response.Instance.Updated = updatedTime
- }
-
- return &response.Instance, err
+ err := r.ExtractInto(&s)
+ return s.Instance, err
}
// InstancePage represents a single page of a paginated instance collection.
@@ -118,71 +92,30 @@
// IsEmpty checks to see whether the collection is empty.
func (page InstancePage) IsEmpty() (bool, error) {
instances, err := ExtractInstances(page)
- if err != nil {
- return true, err
- }
- return len(instances) == 0, nil
+ return len(instances) == 0, err
}
// NextPageURL will retrieve the next page URL.
func (page InstancePage) NextPageURL() (string, error) {
- type resp struct {
- Links []gophercloud.Link `mapstructure:"instances_links"`
+ var s struct {
+ Links []gophercloud.Link `json:"instances_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)
}
// ExtractInstances will convert a generic pagination struct into a more
// relevant slice of Instance structs.
func ExtractInstances(page pagination.Page) ([]Instance, error) {
- casted := page.(InstancePage).Body
-
- var resp struct {
- Instances []Instance `mapstructure:"instances"`
+ r := page.(InstancePage)
+ var s struct {
+ Instances []Instance `json:"instances"`
}
-
- if err := mapstructure.Decode(casted, &resp); err != nil {
- return nil, err
- }
-
- var vals []interface{}
- switch casted.(type) {
- case map[string]interface{}:
- vals = casted.(map[string]interface{})["instances"].([]interface{})
- case map[string][]interface{}:
- vals = casted.(map[string][]interface{})["instances"]
- default:
- return resp.Instances, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
- }
-
- for i, v := range vals {
- val := v.(map[string]interface{})
-
- if t, ok := val["created"].(string); ok && t != "" {
- creationTime, err := time.Parse(time.RFC3339, t)
- if err != nil {
- return resp.Instances, err
- }
- resp.Instances[i].Created = creationTime
- }
-
- if t, ok := val["updated"].(string); ok && t != "" {
- updatedTime, err := time.Parse(time.RFC3339, t)
- if err != nil {
- return resp.Instances, err
- }
- resp.Instances[i].Updated = updatedTime
- }
- }
-
- return resp.Instances, nil
+ err := r.ExtractInto(&s)
+ return s.Instances, err
}
// UserRootResult represents the result of an operation to enable the root user.
@@ -192,17 +125,11 @@
// Extract will extract root user information from a UserRootResult.
func (r UserRootResult) Extract() (*users.User, error) {
- if r.Err != nil {
- return nil, r.Err
+ var s struct {
+ User *users.User `json:"user"`
}
-
- var response struct {
- User users.User `mapstructure:"user"`
- }
-
- err := mapstructure.Decode(r.Body, &response)
-
- return &response.User, err
+ err := r.ExtractInto(&s)
+ return s.User, err
}
// ActionResult represents the result of action requests, such as: restarting