MCPcopy
hub / github.com/tuna/tunasync / GetJSON

Function GetJSON

internal/util.go:95–113  ·  view source on GitHub ↗

GetJSON gets a json response from url

(url string, obj interface{}, client *http.Client)

Source from the content-addressed store, hash-verified

93
94// GetJSON gets a json response from url
95func GetJSON(url string, obj interface{}, client *http.Client) (*http.Response, error) {
96 if client == nil {
97 client, _ = CreateHTTPClient("")
98 }
99
100 resp, err := client.Get(url)
101 if err != nil {
102 return resp, err
103 }
104 if resp.StatusCode != http.StatusOK {
105 return resp, errors.New("HTTP status code is not 200")
106 }
107 defer resp.Body.Close()
108 body, err := io.ReadAll(resp.Body)
109 if err != nil {
110 return resp, err
111 }
112 return resp, json.Unmarshal(body, obj)
113}
114
115// FindAllSubmatchInFile calls re.FindAllSubmatch to find matches in given file
116func FindAllSubmatchInFile(fileName string, re *regexp.Regexp) (matches [][][]byte, err error) {

Callers 3

mainFunction · 0.92
fetchJobStatusMethod · 0.85
TestHTTPServerFunction · 0.85

Calls 3

CreateHTTPClientFunction · 0.85
GetMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestHTTPServerFunction · 0.68