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

Function decodeJSON

pkg/cmd/event/client/client.go:188–199  ·  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

186// decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a
187// request that failed in transit, so callers can tell it apart from a response of an unexpected shape.
188func decodeJSON(resp *http.Response, v any) error {
189 defer resp.Body.Close()
190 body, err := io.ReadAll(resp.Body)
191 if err != nil {
192 return &url.Error{Op: resp.Request.Method, URL: resp.Request.URL.String(), Err: err}
193 }
194
195 if err := json.Unmarshal(body, v); err != nil {
196 return fmt.Errorf("failed to decode response: %w", err)
197 }
198 return nil
199}
200
201func (c *eventClient) DeleteSubscription(ctx context.Context, id string) error {
202 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