blob: 89d9361965591e31742cab5cd6e14b2e760ef7e6 [file] [log] [blame]
Jamie Hannaford940159d2014-11-03 13:04:08 +01001package v1
2
3import (
4 "fmt"
5 "strconv"
6)
7
8// IDSliceToQueryString takes a slice of elements and converts them into a query
9// string. For example, if name=foo and slice=[]int{20, 40, 60}, then the
10// result would be `?name=20&name=40&name=60'
11func IDSliceToQueryString(name string, ids []int) string {
12 str := ""
13 for k, v := range ids {
14 if k == 0 {
15 str += "?"
16 } else {
17 str += "&"
18 }
19 str += fmt.Sprintf("%s=%s", name, strconv.Itoa(v))
20 }
21 return str
22}