Jamie Hannaford | 940159d | 2014-11-03 13:04:08 +0100 | [diff] [blame^] | 1 | package v1 |
| 2 | |
| 3 | import ( |
| 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' |
| 11 | func 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 | } |