MCPcopy
hub / github.com/perkeep/perkeep / GetJSON

Method GetJSON

pkg/client/client.go:1141–1151  ·  view source on GitHub ↗

GetJSON sends a GET request to url, and unmarshals the returned JSON response into data. The URL's host must match the client's configured server.

(ctx context.Context, url string, data interface{})

Source from the content-addressed store, hash-verified

1139// JSON response into data. The URL's host must match the client's
1140// configured server.
1141func (c *Client) GetJSON(ctx context.Context, url string, data interface{}) error {
1142 if !strings.HasPrefix(url, c.discoRoot()) {
1143 return fmt.Errorf("wrong URL (%q) for this server", url)
1144 }
1145 hreq := c.newRequest(ctx, "GET", url)
1146 resp, err := c.expect2XX(hreq)
1147 if err != nil {
1148 return err
1149 }
1150 return httputil.DecodeJSON(resp, data)
1151}
1152
1153// Post is like http://golang.org/pkg/net/http/#Client.Post
1154// but with implementation details like gated requests. The

Callers

nothing calls this directly

Calls 5

discoRootMethod · 0.95
newRequestMethod · 0.95
expect2XXMethod · 0.95
DecodeJSONFunction · 0.92
HasPrefixMethod · 0.80

Tested by

no test coverage detected