-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
38 lines (31 loc) · 816 Bytes
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package clearbank
import (
"net/http"
)
// request is a wrapper around http.Request.
type request struct {
req *http.Request
expectedStatuses []int
decodeTo interface{}
}
func NewRequest(r *http.Request) *request {
return &request{req: r}
}
func (r *request) ExpectStatus(expected ...int) {
r.expectedStatuses = expected
}
func (r *request) DecodeTo(to interface{}) {
r.decodeTo = to
}
// AddQueryParam adds a query parameter to the request.
func (r *request) AddQueryParam(key, value string) {
r.AddQueryParams(map[string]string{key: value})
}
// AddQueryParams adds multiple query parameters to the request.
func (r *request) AddQueryParams(params map[string]string) {
q := r.req.URL.Query()
for k := range params {
q.Add(k, params[k])
}
r.req.URL.RawQuery = q.Encode()
}