diff --git a/gorequest.go b/gorequest.go index 3f4a2e0..68dcaac 100644 --- a/gorequest.go +++ b/gorequest.go @@ -392,7 +392,22 @@ func (s *SuperAgent) queryStruct(content interface{}) *SuperAgent { } else { for k, v := range val { k = strings.ToLower(k) - s.QueryData.Add(k, v.(string)) + var queryVal string + switch t := v.(type) { + case string: + queryVal = t + case float64: + queryVal = strconv.FormatFloat(t, 'f', -1, 64) + case time.Time: + queryVal = t.Format(time.RFC3339) + default: + j, err := json.Marshal(v) + if err != nil { + continue + } + queryVal = string(j) + } + s.QueryData.Add(k, queryVal) } } } diff --git a/gorequest_test.go b/gorequest_test.go index b044ce6..2cf5a74 100644 --- a/gorequest_test.go +++ b/gorequest_test.go @@ -1318,6 +1318,8 @@ func TestQueryFunc(t *testing.T) { case case4_send_map: checkQuery(t, v, "query1", "test1") checkQuery(t, v, "query2", "test2") + checkQuery(t, v, "query3", "3.1415926") + checkQuery(t, v, "query4", "true") } })) defer ts.Close() @@ -1350,6 +1352,8 @@ func TestQueryFunc(t *testing.T) { Query(map[string]interface{}{ "query1": "test1", "query2": "test2", + "query3": 3.1415926, + "query4": true, }). End() }