Introducing new FooResult idiom :shipit:
diff --git a/openstack/networking/v2/ports/requests.go b/openstack/networking/v2/ports/requests.go
index 78c96ab..de880a2 100644
--- a/openstack/networking/v2/ports/requests.go
+++ b/openstack/networking/v2/ports/requests.go
@@ -109,19 +109,15 @@
}
// Get retrieves a specific port based on its unique ID.
-func Get(c *gophercloud.ServiceClient, id string) (*Port, error) {
- var p Port
+func Get(c *gophercloud.ServiceClient, id string) GetResult {
+ var res GetResult
_, err := perigee.Request("GET", getURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &struct {
- Port *Port `json:"port"`
- }{&p},
- OkCodes: []int{200},
+ Results: &res.Resp,
+ OkCodes: []int{200},
})
- if err != nil {
- return nil, err
- }
- return &p, nil
+ res.Err = err
+ return res
}
// CreateOpts represents the attributes used when creating a new port.
@@ -139,7 +135,9 @@
// Create accepts a CreateOpts struct and creates a new network using the values
// provided. You must remember to provide a NetworkID value.
-func Create(c *gophercloud.ServiceClient, opts CreateOpts) (*Port, error) {
+func Create(c *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
+ var res CreateResult
+
type port struct {
NetworkID string `json:"network_id"`
Name *string `json:"name,omitempty"`
@@ -157,7 +155,8 @@
// Validate
if opts.NetworkID == "" {
- return nil, errNetworkIDRequired
+ res.Err = errNetworkIDRequired
+ return res
}
// Populate request body
@@ -180,22 +179,15 @@
}
// Response
- type response struct {
- Port *Port `json:"port"`
- }
- var res response
_, err := perigee.Request("POST", createURL(c), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res,
+ Results: &res.Resp,
OkCodes: []int{201},
DumpReqJson: true,
})
- if err != nil {
- return nil, err
- }
-
- return res.Port, nil
+ res.Err = err
+ return res
}
// UpdateOpts represents the attributes used when updating an existing port.
@@ -210,7 +202,7 @@
// Update accepts a UpdateOpts struct and updates an existing port using the
// values provided.
-func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) (*Port, error) {
+func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
type port struct {
Name *string `json:"name,omitempty"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
@@ -240,28 +232,24 @@
}
// Response
- type response struct {
- Port *Port `json:"port"`
- }
- var res response
+ var res UpdateResult
_, err := perigee.Request("PUT", updateURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
ReqBody: &reqBody,
- Results: &res,
+ Results: &res.Resp,
OkCodes: []int{200, 201},
})
- if err != nil {
- return nil, err
- }
-
- return res.Port, nil
+ res.Err = err
+ return res
}
// Delete accepts a unique ID and deletes the port associated with it.
-func Delete(c *gophercloud.ServiceClient, id string) error {
+func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
+ var res DeleteResult
_, err := perigee.Request("DELETE", deleteURL(c, id), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
OkCodes: []int{204},
})
- return err
+ res.Err = err
+ return res
}