Abstract batch ID query generation
diff --git a/rackspace/lb/v1/common.go b/rackspace/lb/v1/common.go
new file mode 100644
index 0000000..89d9361
--- /dev/null
+++ b/rackspace/lb/v1/common.go
@@ -0,0 +1,22 @@
+package v1
+
+import (
+ "fmt"
+ "strconv"
+)
+
+// IDSliceToQueryString takes a slice of elements and converts them into a query
+// string. For example, if name=foo and slice=[]int{20, 40, 60}, then the
+// result would be `?name=20&name=40&name=60'
+func IDSliceToQueryString(name string, ids []int) string {
+ str := ""
+ for k, v := range ids {
+ if k == 0 {
+ str += "?"
+ } else {
+ str += "&"
+ }
+ str += fmt.Sprintf("%s=%s", name, strconv.Itoa(v))
+ }
+ return str
+}
diff --git a/rackspace/lb/v1/lbs/requests.go b/rackspace/lb/v1/lbs/requests.go
index e4d9f86..5d45c14 100644
--- a/rackspace/lb/v1/lbs/requests.go
+++ b/rackspace/lb/v1/lbs/requests.go
@@ -2,12 +2,12 @@
import (
"errors"
- "strconv"
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/lb/v1"
"github.com/rackspace/gophercloud/rackspace/lb/v1/nodes"
)
@@ -249,14 +249,7 @@
}
url := rootURL(c)
- for k, v := range ids {
- if k == 0 {
- url += "?"
- } else {
- url += "&"
- }
- url += "id=" + strconv.Itoa(v)
- }
+ url += v1.IDSliceToQueryString("id", ids)
_, res.Err = perigee.Request("DELETE", url, perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
diff --git a/rackspace/lb/v1/nodes/requests.go b/rackspace/lb/v1/nodes/requests.go
index a1524dc..e794197 100644
--- a/rackspace/lb/v1/nodes/requests.go
+++ b/rackspace/lb/v1/nodes/requests.go
@@ -3,11 +3,11 @@
import (
"errors"
"fmt"
- "strconv"
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/lb/v1"
)
func List(client *gophercloud.ServiceClient, loadBalancerID int, limit *int) pagination.Pager {
@@ -101,14 +101,7 @@
}
url := rootURL(c, loadBalancerID)
- for k, v := range nodeIDs {
- if k == 0 {
- url += "?"
- } else {
- url += "&"
- }
- url += "id=" + strconv.Itoa(v)
- }
+ url += v1.IDSliceToQueryString("id", nodeIDs)
_, res.Err = perigee.Request("DELETE", url, perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),