WithQuery adds query parameter to request URL. value is converted to string using fmt.Sprint() and urlencoded. Example: req := NewRequestC(config, "PUT", "http://example.com/path") req.WithQuery("a", 123) req.WithQuery("b", "foo") // URL is now http://example.com/path?a=123&b=foo
(key string, value interface{})
| 1170 | // req.WithQuery("b", "foo") |
| 1171 | // // URL is now http://example.com/path?a=123&b=foo |
| 1172 | func (r *Request) WithQuery(key string, value interface{}) *Request { |
| 1173 | opChain := r.chain.enter("WithQuery()") |
| 1174 | defer opChain.leave() |
| 1175 | |
| 1176 | r.mu.Lock() |
| 1177 | defer r.mu.Unlock() |
| 1178 | |
| 1179 | if opChain.failed() { |
| 1180 | return r |
| 1181 | } |
| 1182 | |
| 1183 | if !r.checkOrder(opChain, "WithQuery()") { |
| 1184 | return r |
| 1185 | } |
| 1186 | |
| 1187 | if value == nil { |
| 1188 | opChain.fail(AssertionFailure{ |
| 1189 | Type: AssertUsage, |
| 1190 | Errors: []error{ |
| 1191 | errors.New("unexpected nil argument"), |
| 1192 | }, |
| 1193 | }) |
| 1194 | return r |
| 1195 | } |
| 1196 | |
| 1197 | if r.query == nil { |
| 1198 | r.query = make(url.Values) |
| 1199 | } |
| 1200 | r.query.Add(key, fmt.Sprint(value)) |
| 1201 | |
| 1202 | return r |
| 1203 | } |
| 1204 | |
| 1205 | // WithQueryObject adds multiple query parameters to request URL. |
| 1206 | // |