package netreq import ( "fmt" "io" "net/http" ) // Makes a GET request to the specified URL and returns the JSON response // as a byte slice. If the request fails, it returns an error. func GetJSON(url string) ([]byte, error) { fmt.Println(url) res, err := http.Get(url) if err != nil { return nil, err } body, err := io.ReadAll(res.Body) res.Body.Close() if res.StatusCode > 299 { return nil, fmt.Errorf("request failed with status code %d: %s", res.StatusCode, string(body)) } if err != nil { return nil, err } return body, nil }