Get performs an HTTP GET and returns the bytes and/or an error. Any non-200 return code is returned as an error.
(path string)
| 163 | // Get performs an HTTP GET and returns the bytes and/or an error. Any non-200 |
| 164 | // return code is returned as an error. |
| 165 | func (p *Process) Get(path string) ([]byte, error) { |
| 166 | client := &http.Client{ |
| 167 | Timeout: 30 * time.Second, |
| 168 | Transport: &http.Transport{ |
| 169 | DialContext: dialer.DialContext, |
| 170 | Proxy: http.ProxyFromEnvironment, |
| 171 | DisableKeepAlives: true, |
| 172 | }, |
| 173 | } |
| 174 | |
| 175 | url := fmt.Sprintf("http://%s%s", p.addr, path) |
| 176 | req, err := http.NewRequest(http.MethodGet, url, nil) |
| 177 | if err != nil { |
| 178 | return nil, err |
| 179 | } |
| 180 | |
| 181 | req.Header.Add("X-Api-Key", APIKey) |
| 182 | |
| 183 | resp, err := client.Do(req) |
| 184 | if err != nil { |
| 185 | return nil, err |
| 186 | } |
| 187 | |
| 188 | return p.readResponse(resp) |
| 189 | } |
| 190 | |
| 191 | // Post performs an HTTP POST and returns the bytes and/or an error. Any |
| 192 | // non-200 return code is returned as an error. |
no test coverage detected