getResponse performs the API call and returns the response's link header values. If the "Link" header is missing, the returned slice will be nil.
(client *http.Client, host, path string, data interface{})
| 70 | // getResponse performs the API call and returns the response's link header values. |
| 71 | // If the "Link" header is missing, the returned slice will be nil. |
| 72 | func getResponse(client *http.Client, host, path string, data interface{}) ([]string, error) { |
| 73 | url := ghinstance.RESTPrefix(host) + path |
| 74 | req, err := http.NewRequest("GET", url, nil) |
| 75 | if err != nil { |
| 76 | return nil, err |
| 77 | } |
| 78 | |
| 79 | req.Header.Set("Content-Type", "application/json; charset=utf-8") |
| 80 | resp, err := client.Do(req) |
| 81 | if err != nil { |
| 82 | return nil, err |
| 83 | } |
| 84 | defer resp.Body.Close() |
| 85 | |
| 86 | success := resp.StatusCode >= 200 && resp.StatusCode < 300 |
| 87 | if !success { |
| 88 | return nil, errors.New("api call failed") |
| 89 | } |
| 90 | |
| 91 | links := resp.Header["Link"] |
| 92 | |
| 93 | if resp.StatusCode == http.StatusNoContent { |
| 94 | return links, nil |
| 95 | } |
| 96 | |
| 97 | b, err := io.ReadAll(resp.Body) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | err = json.Unmarshal(b, &data) |
| 103 | if err != nil { |
| 104 | return nil, err |
| 105 | } |
| 106 | |
| 107 | return links, nil |
| 108 | } |
no test coverage detected