Fixing minor issues such as weakly typed decoding
diff --git a/openstack/db/v1/flavors/fixtures.go b/openstack/db/v1/flavors/fixtures.go
index df70898..f0016bc 100644
--- a/openstack/db/v1/flavors/fixtures.go
+++ b/openstack/db/v1/flavors/fixtures.go
@@ -2,7 +2,6 @@
import (
"fmt"
- "strconv"
"testing"
"github.com/rackspace/gophercloud/testhelper/fixture"
@@ -27,9 +26,9 @@
`
var (
- flavorID = 1
+ flavorID = "{flavorID}"
_baseURL = "/flavors"
- resURL = "/flavors/" + strconv.Itoa(flavorID)
+ resURL = "/flavors/" + flavorID
)
var (
diff --git a/openstack/db/v1/flavors/requests.go b/openstack/db/v1/flavors/requests.go
index beeeddc..fa34446 100644
--- a/openstack/db/v1/flavors/requests.go
+++ b/openstack/db/v1/flavors/requests.go
@@ -17,7 +17,7 @@
}
// Get will retrieve information for a specified hardware flavor.
-func Get(client *gophercloud.ServiceClient, id int) GetResult {
+func Get(client *gophercloud.ServiceClient, id string) GetResult {
var gr GetResult
_, gr.Err = client.Request("GET", getURL(client, id), gophercloud.RequestOpts{
diff --git a/openstack/db/v1/flavors/results.go b/openstack/db/v1/flavors/results.go
index 2089f67..2cee010 100644
--- a/openstack/db/v1/flavors/results.go
+++ b/openstack/db/v1/flavors/results.go
@@ -21,7 +21,12 @@
Flavor Flavor `mapstructure:"flavor"`
}
- err := mapstructure.Decode(gr.Body, &result)
+ decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
+ WeaklyTypedInput: true,
+ Result: &result,
+ })
+
+ err = decoder.Decode(gr.Body)
return &result.Flavor, err
}
@@ -76,6 +81,12 @@
Flavors []Flavor `mapstructure:"flavors"`
}
- err := mapstructure.Decode(casted, &container)
+ decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
+ WeaklyTypedInput: true,
+ Result: &container,
+ })
+
+ err = decoder.Decode(casted)
+
return container.Flavors, err
}
diff --git a/openstack/db/v1/flavors/urls.go b/openstack/db/v1/flavors/urls.go
index 3b3e8da..80da11f 100644
--- a/openstack/db/v1/flavors/urls.go
+++ b/openstack/db/v1/flavors/urls.go
@@ -1,13 +1,9 @@
package flavors
-import (
- "strconv"
+import "github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud"
-)
-
-func getURL(client *gophercloud.ServiceClient, id int) string {
- return client.ServiceURL("flavors", strconv.Itoa(id))
+func getURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("flavors", id)
}
func listURL(client *gophercloud.ServiceClient) string {
diff --git a/rackspace/db/v1/flavors/delegate.go b/rackspace/db/v1/flavors/delegate.go
index fd2608d..689b81e 100644
--- a/rackspace/db/v1/flavors/delegate.go
+++ b/rackspace/db/v1/flavors/delegate.go
@@ -12,6 +12,6 @@
}
// Get retrieves the details for a particular flavor.
-func Get(client *gophercloud.ServiceClient, flavorID int) os.GetResult {
+func Get(client *gophercloud.ServiceClient, flavorID string) os.GetResult {
return os.Get(client, flavorID)
}
diff --git a/rackspace/db/v1/flavors/delegate_test.go b/rackspace/db/v1/flavors/delegate_test.go
index 4f51776..f5f6442 100644
--- a/rackspace/db/v1/flavors/delegate_test.go
+++ b/rackspace/db/v1/flavors/delegate_test.go
@@ -26,7 +26,7 @@
expected := []os.Flavor{
os.Flavor{
- ID: 1,
+ ID: "1",
Name: "m1.tiny",
RAM: 512,
Links: []gophercloud.Link{
@@ -35,7 +35,7 @@
},
},
os.Flavor{
- ID: 2,
+ ID: "2",
Name: "m1.small",
RAM: 1024,
Links: []gophercloud.Link{
@@ -44,7 +44,7 @@
},
},
os.Flavor{
- ID: 3,
+ ID: "3",
Name: "m1.medium",
RAM: 2048,
Links: []gophercloud.Link{
@@ -53,7 +53,7 @@
},
},
os.Flavor{
- ID: 4,
+ ID: "4",
Name: "m1.large",
RAM: 4096,
Links: []gophercloud.Link{
@@ -83,7 +83,7 @@
th.AssertNoErr(t, err)
expected := &os.Flavor{
- ID: 1,
+ ID: "1",
Name: "m1.tiny",
RAM: 512,
Links: []gophercloud.Link{
diff --git a/rackspace/db/v1/instances/delegate_test.go b/rackspace/db/v1/instances/delegate_test.go
index 4a13286..03a4828 100644
--- a/rackspace/db/v1/instances/delegate_test.go
+++ b/rackspace/db/v1/instances/delegate_test.go
@@ -5,6 +5,7 @@
"github.com/rackspace/gophercloud"
osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
+ "github.com/rackspace/gophercloud/openstack/db/v1/flavors"
os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
"github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
@@ -23,7 +24,7 @@
Created: "2014-02-13T21:47:13",
Updated: "2014-02-13T21:47:13",
Datastore: datastores.DatastorePartial{Type: "mysql", Version: "5.6"},
- Flavor: os.Flavor{
+ Flavor: flavors.Flavor{
ID: "1",
Links: []gophercloud.Link{
gophercloud.Link{Href: "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", Rel: "self"},
diff --git a/rackspace/db/v1/instances/requests_test.go b/rackspace/db/v1/instances/requests_test.go
index 0805dd8..aab057d 100644
--- a/rackspace/db/v1/instances/requests_test.go
+++ b/rackspace/db/v1/instances/requests_test.go
@@ -4,6 +4,7 @@
"testing"
"github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/openstack/db/v1/flavors"
os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/rackspace/db/v1/backups"
@@ -156,7 +157,7 @@
ID: "3c691f06-bf9a-4618-b7ec-2817ce0cf254",
IP: []string{"10.0.0.3"},
Volume: os.Volume{Size: 1},
- Flavor: os.Flavor{ID: "9"},
+ Flavor: flavors.Flavor{ID: "9"},
Datastore: datastores.DatastorePartial{Version: "5.6", Type: "mysql"},
ReplicaOf: &Instance{
ID: "8b499b45-52d6-402d-b398-f9d8f279c69a",
@@ -197,7 +198,7 @@
Used: 0.54,
Size: 1,
},
- Flavor: os.Flavor{ID: "9"},
+ Flavor: flavors.Flavor{ID: "9"},
Datastore: datastores.DatastorePartial{
Version: "5.6",
Type: "mysql",