(method string, url url.URL, body interface{})
| 85 | } |
| 86 | |
| 87 | func (r *RESTClient) sendRequest(method string, url url.URL, body interface{}) (*http.Response, error) { |
| 88 | var bodyReader io.Reader |
| 89 | if body != nil { |
| 90 | if bodyBytes, err := json.Marshal(body); err != nil { |
| 91 | return nil, errors.Wrap(err, "failed to serialize json body") |
| 92 | } else { |
| 93 | bodyReader = bytes.NewBuffer(bodyBytes) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | req, err := http.NewRequest(method, url.String(), bodyReader) |
| 98 | if err != nil { |
| 99 | return nil, errors.Wrapf(err, "can't create %s request", method) |
| 100 | } |
| 101 | req.Header.Set("User-Agent", r.userAgent) |
| 102 | if bodyReader != nil { |
| 103 | req.Header.Set("Content-Type", jsonContentType) |
| 104 | } |
| 105 | req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", r.authToken)) |
| 106 | req.Header.Add("Accept", "application/json;version=1") |
| 107 | return r.client.Do(req) |
| 108 | } |
| 109 | |
| 110 | func parseResponseEnvelope(reader io.Reader) (*response, error) { |
| 111 | // Schema for Tunnelstore responses in the v1 API. |
no test coverage detected