remove mapstructure from blockstorage,cdn,compute,db pkgs
diff --git a/openstack/db/v1/configurations/results.go b/openstack/db/v1/configurations/results.go
index 5128b01..a708abd 100644
--- a/openstack/db/v1/configurations/results.go
+++ b/openstack/db/v1/configurations/results.go
@@ -1,22 +1,19 @@
package configurations
import (
- "fmt"
- "reflect"
"time"
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Config represents a configuration group API resource.
type Config struct {
- Created time.Time `mapstructure:"-"`
- Updated time.Time `mapstructure:"-"`
- DatastoreName string `mapstructure:"datastore_name"`
- DatastoreVersionID string `mapstructure:"datastore_version_id"`
- DatastoreVersionName string `mapstructure:"datastore_version_name"`
+ Created time.Time `json:"created"`
+ Updated time.Time `json:"updated"`
+ DatastoreName string `json:"datastore_name"`
+ DatastoreVersionID string `json:"datastore_version_id"`
+ DatastoreVersionName string `json:"datastore_version_name"`
Description string
ID string
Name string
@@ -31,55 +28,17 @@
// IsEmpty indicates whether a ConfigPage is empty.
func (r ConfigPage) IsEmpty() (bool, error) {
is, err := ExtractConfigs(r)
- if err != nil {
- return true, err
- }
- return len(is) == 0, nil
+ return len(is) == 0, err
}
// ExtractConfigs will retrieve a slice of Config structs from a page.
func ExtractConfigs(page pagination.Page) ([]Config, error) {
- casted := page.(ConfigPage).Body
-
- var resp struct {
- Configs []Config `mapstructure:"configurations" json:"configurations"`
+ r := page.(ConfigPage)
+ var s struct {
+ Configs []Config `json:"configurations"`
}
-
- 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{})["configurations"].([]interface{})
- case map[string][]interface{}:
- vals = casted.(map[string][]interface{})["configurations"]
- default:
- return resp.Configs, 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.Configs, err
- }
- resp.Configs[i].Created = creationTime
- }
-
- if t, ok := val["updated"].(string); ok && t != "" {
- updatedTime, err := time.Parse(time.RFC3339, t)
- if err != nil {
- return resp.Configs, err
- }
- resp.Configs[i].Updated = updatedTime
- }
- }
-
- return resp.Configs, nil
+ err := r.ExtractInto(&s)
+ return s.Configs, err
}
type commonResult struct {
@@ -88,34 +47,11 @@
// Extract will retrieve a Config resource from an operation result.
func (r commonResult) Extract() (*Config, error) {
- if r.Err != nil {
- return nil, r.Err
+ var s struct {
+ Config *Config `json:"configuration"`
}
-
- var response struct {
- Config Config `mapstructure:"configuration"`
- }
-
- err := mapstructure.Decode(r.Body, &response)
- val := r.Body.(map[string]interface{})["configuration"].(map[string]interface{})
-
- if t, ok := val["created"].(string); ok && t != "" {
- creationTime, err := time.Parse(time.RFC3339, t)
- if err != nil {
- return &response.Config, err
- }
- response.Config.Created = creationTime
- }
-
- if t, ok := val["updated"].(string); ok && t != "" {
- updatedTime, err := time.Parse(time.RFC3339, t)
- if err != nil {
- return &response.Config, err
- }
- response.Config.Updated = updatedTime
- }
-
- return &response.Config, err
+ err := r.ExtractInto(&s)
+ return s.Config, err
}
// GetResult represents the result of a Get operation.
@@ -145,10 +81,10 @@
// Param represents a configuration parameter API resource.
type Param struct {
- Max int
- Min int
+ Max float64
+ Min float64
Name string
- RestartRequired bool `mapstructure:"restart_required" json:"restart_required"`
+ RestartRequired bool `json:"restart_required"`
Type string
}
@@ -160,22 +96,17 @@
// IsEmpty indicates whether a ParamPage is empty.
func (r ParamPage) IsEmpty() (bool, error) {
is, err := ExtractParams(r)
- if err != nil {
- return true, err
- }
- return len(is) == 0, nil
+ return len(is) == 0, err
}
// ExtractParams will retrieve a slice of Param structs from a page.
func ExtractParams(page pagination.Page) ([]Param, error) {
- casted := page.(ParamPage).Body
-
- var resp struct {
- Params []Param `mapstructure:"configuration-parameters" json:"configuration-parameters"`
+ r := page.(ParamPage)
+ var s struct {
+ Params []Param `json:"configuration-parameters"`
}
-
- err := mapstructure.Decode(casted, &resp)
- return resp.Params, err
+ err := r.ExtractInto(&s)
+ return s.Params, err
}
// ParamResult represents the result of an operation which retrieves details
@@ -186,12 +117,7 @@
// Extract will retrieve a param from an operation result.
func (r ParamResult) Extract() (*Param, error) {
- if r.Err != nil {
- return nil, r.Err
- }
-
- var param Param
-
- err := mapstructure.Decode(r.Body, ¶m)
- return ¶m, err
+ var s Param
+ err := r.ExtractInto(&s)
+ return &s, err
}