alter BuildQuery to handle slices
diff --git a/params.go b/params.go
index 509a7c7..4d0f1e6 100644
--- a/params.go
+++ b/params.go
@@ -145,8 +145,12 @@
case reflect.Bool:
params.Add(tags[0], strconv.FormatBool(v.Bool()))
case reflect.Slice:
- switch f.Type {
- case reflect.TypeOf([]string{}):
+ switch v.Type().Elem() {
+ case reflect.TypeOf(0):
+ for i := 0; i < v.Len(); i++ {
+ params.Add(tags[0], strconv.FormatInt(v.Index(i).Int(), 10))
+ }
+ default:
for i := 0; i < v.Len(); i++ {
params.Add(tags[0], v.Index(i).String())
}
diff --git a/params_test.go b/params_test.go
index f314a9e..2f40eec 100644
--- a/params_test.go
+++ b/params_test.go
@@ -34,18 +34,23 @@
}
func TestBuildQueryString(t *testing.T) {
+ type testVar string
opts := struct {
- J int `q:"j"`
- R string `q:"r,required"`
- C bool `q:"c"`
- S []string `q:"s"`
+ J int `q:"j"`
+ R string `q:"r,required"`
+ C bool `q:"c"`
+ S []string `q:"s"`
+ TS []testVar `q:"ts"`
+ TI []int `q:"ti"`
}{
- J: 2,
- R: "red",
- C: true,
- S: []string{"one", "two", "three"},
+ J: 2,
+ R: "red",
+ C: true,
+ S: []string{"one", "two", "three"},
+ TS: []testVar{"a", "b"},
+ TI: []int{1, 2},
}
- expected := &url.URL{RawQuery: "c=true&j=2&r=red&s=one&s=two&s=three"}
+ expected := &url.URL{RawQuery: "c=true&j=2&r=red&s=one&s=two&s=three&ti=1&ti=2&ts=a&ts=b"}
actual, err := BuildQueryString(&opts)
if err != nil {
t.Errorf("Error building query string: %v", err)
@@ -53,10 +58,12 @@
th.CheckDeepEquals(t, expected, actual)
opts = struct {
- J int `q:"j"`
- R string `q:"r,required"`
- C bool `q:"c"`
- S []string `q:"s"`
+ J int `q:"j"`
+ R string `q:"r,required"`
+ C bool `q:"c"`
+ S []string `q:"s"`
+ TS []testVar `q:"ts"`
+ TI []int `q:"ti"`
}{
J: 2,
C: true,