MCPcopy Create free account
hub / github.com/cli/cli / getResponse

Function getResponse

pkg/cmd/repo/garden/http.go:83–118  ·  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, url safeurl.SafeURL, data interface{})

Source from the content-addressed store, hash-verified

81// getResponse performs the API call and returns the response's link header values.
82// If the "Link" header is missing, the returned slice will be nil.
83func getResponse(client *http.Client, url safeurl.SafeURL, data interface{}) ([]string, error) {
84 req, err := http.NewRequest("GET", url.String(), nil)
85 if err != nil {
86 return nil, err
87 }
88
89 req.Header.Set("Content-Type", "application/json; charset=utf-8")
90 resp, err := client.Do(req)
91 if err != nil {
92 return nil, err
93 }
94 defer resp.Body.Close()
95
96 success := resp.StatusCode >= 200 && resp.StatusCode < 300
97 if !success {
98 return nil, errors.New("api call failed")
99 }
100
101 links := resp.Header["Link"]
102
103 if resp.StatusCode == http.StatusNoContent {
104 return links, nil
105 }
106
107 b, err := io.ReadAll(resp.Body)
108 if err != nil {
109 return nil, err
110 }
111
112 err = json.Unmarshal(b, &data)
113 if err != nil {
114 return nil, err
115 }
116
117 return links, nil
118}

Callers 1

getCommitsFunction · 0.85

Calls 4

StringMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected