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

Function decodeJSON

pkg/cmd/event/client/client.go:177–188  ·  view source on GitHub ↗

decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a request that failed in transit, so callers can tell it apart from a response of an unexpected shape.

(resp *http.Response, v any)

Source from the content-addressed store, hash-verified

175// decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a
176// request that failed in transit, so callers can tell it apart from a response of an unexpected shape.
177func decodeJSON(resp *http.Response, v any) error {
178 defer resp.Body.Close()
179 body, err := io.ReadAll(resp.Body)
180 if err != nil {
181 return &url.Error{Op: resp.Request.Method, URL: resp.Request.URL.String(), Err: err}
182 }
183
184 if err := json.Unmarshal(body, v); err != nil {
185 return fmt.Errorf("failed to decode response: %w", err)
186 }
187 return nil
188}
189
190func (c *eventClient) DeleteSubscription(ctx context.Context, id string) error {
191 if !SupportedHost(c.host) {

Callers 1

CreateSubscriptionMethod · 0.70

Calls 3

CloseMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected