MCPcopy
hub / github.com/cli/cli / getResponse

Function getResponse

pkg/cmd/repo/garden/http.go:72–108  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

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.
72func 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}

Callers 1

getCommitsFunction · 0.85

Calls 4

RESTPrefixFunction · 0.92
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected