remove mapstructure from blockstorage,cdn,compute,db pkgs
diff --git a/openstack/compute/v2/flavors/results.go b/openstack/compute/v2/flavors/results.go
index 785cbe2..3f14e76 100644
--- a/openstack/compute/v2/flavors/results.go
+++ b/openstack/compute/v2/flavors/results.go
@@ -2,9 +2,7 @@
import (
"errors"
- "reflect"
- "github.com/mitchellh/mapstructure"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -18,48 +16,35 @@
}
// Extract provides access to the individual Flavor returned by the Get function.
-func (gr GetResult) Extract() (*Flavor, error) {
- if gr.Err != nil {
- return nil, gr.Err
+func (r GetResult) Extract() (*Flavor, error) {
+ var s struct {
+ Flavor *Flavor `json:"flavor"`
}
-
- var result struct {
- Flavor Flavor `mapstructure:"flavor"`
- }
-
- cfg := &mapstructure.DecoderConfig{
- DecodeHook: defaulter,
- Result: &result,
- }
- decoder, err := mapstructure.NewDecoder(cfg)
- if err != nil {
- return nil, err
- }
- err = decoder.Decode(gr.Body)
- return &result.Flavor, err
+ err := r.ExtractInto(&s)
+ return s.Flavor, err
}
// Flavor records represent (virtual) hardware configurations for server resources in a region.
type Flavor struct {
// The Id field contains the flavor's unique identifier.
// For example, this identifier will be useful when specifying which hardware configuration to use for a new server instance.
- ID string `mapstructure:"id"`
+ ID string `json:"id"`
// The Disk and RA< fields provide a measure of storage space offered by the flavor, in GB and MB, respectively.
- Disk int `mapstructure:"disk"`
- RAM int `mapstructure:"ram"`
+ Disk int `json:"disk"`
+ RAM int `json:"ram"`
// The Name field provides a human-readable moniker for the flavor.
- Name string `mapstructure:"name"`
+ Name string `json:"name"`
- RxTxFactor float64 `mapstructure:"rxtx_factor"`
+ RxTxFactor float64 `json:"rxtx_factor"`
// Swap indicates how much space is reserved for swap.
// If not provided, this field will be set to 0.
- Swap int `mapstructure:"swap"`
+ Swap int `json:"swap"`
// VCPUs indicates how many (virtual) CPUs are available for this flavor.
- VCPUs int `mapstructure:"vcpus"`
+ VCPUs int `json:"vcpus"`
}
// FlavorPage contains a single page of the response from a List call.
@@ -68,55 +53,29 @@
}
// IsEmpty determines if a page contains any results.
-func (p FlavorPage) IsEmpty() (bool, error) {
- flavors, err := ExtractFlavors(p)
- if err != nil {
- return true, err
- }
- return len(flavors) == 0, nil
+func (page FlavorPage) IsEmpty() (bool, error) {
+ flavors, err := ExtractFlavors(page)
+ return len(flavors) == 0, err
}
// NextPageURL uses the response's embedded link reference to navigate to the next page of results.
-func (p FlavorPage) NextPageURL() (string, error) {
- type resp struct {
- Links []gophercloud.Link `mapstructure:"flavors_links"`
+func (page FlavorPage) NextPageURL() (string, error) {
+ var s struct {
+ Links []gophercloud.Link `json:"flavors_links"`
}
-
- var r resp
- err := mapstructure.Decode(p.Body, &r)
+ err := page.ExtractInto(&s)
if err != nil {
return "", err
}
-
- return gophercloud.ExtractNextURL(r.Links)
-}
-
-func defaulter(from, to reflect.Kind, v interface{}) (interface{}, error) {
- if (from == reflect.String) && (to == reflect.Int) {
- return 0, nil
- }
- return v, nil
+ return gophercloud.ExtractNextURL(s.Links)
}
// ExtractFlavors provides access to the list of flavors in a page acquired from the List operation.
func ExtractFlavors(page pagination.Page) ([]Flavor, error) {
- casted := page.(FlavorPage).Body
- var container struct {
- Flavors []Flavor `mapstructure:"flavors"`
+ r := page.(FlavorPage)
+ var s struct {
+ Flavors []Flavor `json:"flavors"`
}
-
- cfg := &mapstructure.DecoderConfig{
- DecodeHook: defaulter,
- Result: &container,
- }
- decoder, err := mapstructure.NewDecoder(cfg)
- if err != nil {
- return container.Flavors, err
- }
- err = decoder.Decode(casted)
- if err != nil {
- return container.Flavors, err
- }
-
- return container.Flavors, nil
+ err := r.ExtractInto(&s)
+ return s.Flavors, err
}