Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 7d51cf1

Browse files
author
Jamie Hannaford
committed
Removing awkward nested maps
1 parent 257c8dc commit 7d51cf1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

openstack/db/v1/instances/requests.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,16 @@ func RestartService(client *gophercloud.ServiceClient, id string) ActionResult {
174174
func ResizeInstance(client *gophercloud.ServiceClient, id, flavorRef string) ActionResult {
175175
var res ActionResult
176176

177-
reqBody := map[string]map[string]string{
178-
"resize": map[string]string{
179-
"flavorRef": flavorRef,
180-
},
177+
type resize struct {
178+
FlavorRef string `json:"flavorRef"`
181179
}
182180

181+
type req struct {
182+
Resize resize `json:"resize"`
183+
}
184+
185+
reqBody := req{Resize: resize{FlavorRef: flavorRef}}
186+
183187
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
184188
JSONBody: reqBody,
185189
OkCodes: []int{202},
@@ -194,12 +198,20 @@ func ResizeInstance(client *gophercloud.ServiceClient, id, flavorRef string) Act
194198
func ResizeVolume(client *gophercloud.ServiceClient, id string, size int) ActionResult {
195199
var res ActionResult
196200

197-
reqBody := map[string]map[string]map[string]int{
198-
"resize": map[string]map[string]int{
199-
"volume": map[string]int{"size": size},
200-
},
201+
type volume struct {
202+
Size int `json:"size"`
203+
}
204+
205+
type resize struct {
206+
Volume volume `json:"volume"`
207+
}
208+
209+
type req struct {
210+
Resize resize `json:"resize"`
201211
}
202212

213+
reqBody := req{Resize: resize{Volume: volume{Size: size}}}
214+
203215
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
204216
JSONBody: reqBody,
205217
OkCodes: []int{202},

0 commit comments

Comments
 (0)