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

Method RESTWithNext

api/client.go:113–148  ·  view source on GitHub ↗
(hostname string, method string, p string, body io.Reader, data interface{})

Source from the content-addressed store, hash-verified

111}
112
113func (c Client) RESTWithNext(hostname string, method string, p string, body io.Reader, data interface{}) (string, error) {
114 opts := clientOptions(hostname, c.http.Transport)
115 restClient, err := ghAPI.NewRESTClient(opts)
116 if err != nil {
117 return "", err
118 }
119
120 resp, err := restClient.Request(method, p, body)
121 if err != nil {
122 return "", handleResponse(err)
123 }
124 defer resp.Body.Close()
125
126 if resp.StatusCode == http.StatusNoContent {
127 return "", nil
128 }
129
130 b, err := io.ReadAll(resp.Body)
131 if err != nil {
132 return "", err
133 }
134
135 err = json.Unmarshal(b, &data)
136 if err != nil {
137 return "", err
138 }
139
140 var next string
141 for _, m := range linkRE.FindAllStringSubmatch(resp.Header.Get("Link"), -1) {
142 if len(m) > 2 && m[2] == "next" {
143 next = m[1]
144 }
145 }
146
147 return next, nil
148}
149
150// HandleHTTPError parses a http.Response into a HTTPError.
151//

Callers

nothing calls this directly

Calls 4

clientOptionsFunction · 0.85
handleResponseFunction · 0.85
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected