File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 14
14
// "X-Version": version,
15
15
// })
16
16
//
17
+ // Set query string: Using SetQUERY to generate query string data.
18
+ //
19
+ // SetQUERY(gofight.H{
20
+ // "a": "1",
21
+ // "b": "2",
22
+ // })
23
+ //
17
24
// POST FORM Data: Using SetFORM to generate form data.
18
25
//
19
26
// SetFORM(gofight.H{
@@ -212,6 +219,23 @@ func (rc *RequestConfig) SetFORM(body H) *RequestConfig {
212
219
return rc
213
220
}
214
221
222
+ // SetQUERY supply query string.
223
+ func (rc * RequestConfig ) SetQUERY (query H ) * RequestConfig {
224
+ f := make (url.Values )
225
+
226
+ for k , v := range query {
227
+ f .Set (k , v )
228
+ }
229
+
230
+ if strings .Contains (rc .Path , "?" ) {
231
+ rc .Path = rc .Path + "&" + f .Encode ()
232
+ } else {
233
+ rc .Path = rc .Path + "?" + f .Encode ()
234
+ }
235
+
236
+ return rc
237
+ }
238
+
215
239
// SetBody supply raw body.
216
240
func (rc * RequestConfig ) SetBody (body string ) * RequestConfig {
217
241
if len (body ) > 0 {
Original file line number Diff line number Diff line change @@ -380,3 +380,23 @@ func TestEchoOptions(t *testing.T) {
380
380
assert .Equal (t , http .StatusOK , r .Status ())
381
381
})
382
382
}
383
+
384
+ func TestSetQueryString (t * testing.T ) {
385
+ r := New ()
386
+
387
+ r .GET ("/hello" ).
388
+ SetQUERY (H {
389
+ "a" : "1" ,
390
+ "b" : "2" ,
391
+ })
392
+
393
+ assert .Equal (t , "/hello?a=1&b=2" , r .Path )
394
+
395
+ r .GET ("/hello?foo=bar" ).
396
+ SetQUERY (H {
397
+ "a" : "1" ,
398
+ "b" : "2" ,
399
+ })
400
+
401
+ assert .Equal (t , "/hello?foo=bar&a=1&b=2" , r .Path )
402
+ }
You can’t perform that action at this time.
0 commit comments