Moving MaybeString to root package
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 567b31f..0d74eb5 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -16,16 +16,6 @@
TenantID string
}
-func ptrToStr(val *bool) string {
- if *val == true {
- return "true"
- } else if *val == false {
- return "false"
- } else {
- return ""
- }
-}
-
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the network attributes you want to see returned. SortKey allows you to sort
@@ -57,13 +47,13 @@
q["name"] = opts.Name
}
if opts.AdminStateUp != nil {
- q["admin_state_up"] = ptrToStr(opts.AdminStateUp)
+ q["admin_state_up"] = strconv.FormatBool(*opts.AdminStateUp)
}
if opts.TenantID != "" {
q["tenant_id"] = opts.TenantID
}
if opts.Shared != nil {
- q["shared"] = ptrToStr(opts.Shared)
+ q["shared"] = strconv.FormatBool(*opts.Shared)
}
if opts.ID != "" {
q["id"] = opts.ID
diff --git a/openstack/networking/v2/ports/requests.go b/openstack/networking/v2/ports/requests.go
index de880a2..3b7e605 100644
--- a/openstack/networking/v2/ports/requests.go
+++ b/openstack/networking/v2/ports/requests.go
@@ -9,13 +9,6 @@
"github.com/rackspace/gophercloud/pagination"
)
-func maybeString(original string) *string {
- if original != "" {
- return &original
- }
- return nil
-}
-
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the port attributes you want to see returned. SortKey allows you to sort
@@ -162,12 +155,12 @@
// Populate request body
reqBody := request{Port: port{
NetworkID: opts.NetworkID,
- Name: maybeString(opts.Name),
+ Name: gophercloud.MaybeString(opts.Name),
AdminStateUp: opts.AdminStateUp,
- TenantID: maybeString(opts.TenantID),
- MACAddress: maybeString(opts.MACAddress),
- DeviceID: maybeString(opts.DeviceID),
- DeviceOwner: maybeString(opts.DeviceOwner),
+ TenantID: gophercloud.MaybeString(opts.TenantID),
+ MACAddress: gophercloud.MaybeString(opts.MACAddress),
+ DeviceID: gophercloud.MaybeString(opts.DeviceID),
+ DeviceOwner: gophercloud.MaybeString(opts.DeviceOwner),
}}
if opts.FixedIPs != nil {
@@ -217,10 +210,10 @@
// Populate request body
reqBody := request{Port: port{
- Name: maybeString(opts.Name),
+ Name: gophercloud.MaybeString(opts.Name),
AdminStateUp: opts.AdminStateUp,
- DeviceID: maybeString(opts.DeviceID),
- DeviceOwner: maybeString(opts.DeviceOwner),
+ DeviceID: gophercloud.MaybeString(opts.DeviceID),
+ DeviceOwner: gophercloud.MaybeString(opts.DeviceOwner),
}}
if opts.FixedIPs != nil {
diff --git a/openstack/networking/v2/subnets/requests.go b/openstack/networking/v2/subnets/requests.go
index 7552458..9cbf5ab 100644
--- a/openstack/networking/v2/subnets/requests.go
+++ b/openstack/networking/v2/subnets/requests.go
@@ -9,13 +9,6 @@
"github.com/rackspace/gophercloud/pagination"
)
-func maybeString(original string) *string {
- if original != "" {
- return &original
- }
- return nil
-}
-
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Filtering is achieved by passing in struct field values that map to
// the subnet attributes you want to see returned. SortKey allows you to sort
@@ -161,9 +154,9 @@
reqBody := request{Subnet: subnet{
NetworkID: opts.NetworkID,
CIDR: opts.CIDR,
- Name: maybeString(opts.Name),
- TenantID: maybeString(opts.TenantID),
- GatewayIP: maybeString(opts.GatewayIP),
+ Name: gophercloud.MaybeString(opts.Name),
+ TenantID: gophercloud.MaybeString(opts.TenantID),
+ GatewayIP: gophercloud.MaybeString(opts.GatewayIP),
EnableDHCP: opts.EnableDHCP,
}}
@@ -215,8 +208,8 @@
}
reqBody := request{Subnet: subnet{
- Name: maybeString(opts.Name),
- GatewayIP: maybeString(opts.GatewayIP),
+ Name: gophercloud.MaybeString(opts.Name),
+ GatewayIP: gophercloud.MaybeString(opts.GatewayIP),
EnableDHCP: opts.EnableDHCP,
}}