Is there a library / package that returns a json string received in response to an HTTP request. It's pretty simple, so I can write my own, but would prefer the existing / tested code to reinvent the wheel.
I currently have:
func getJsonStr(url string) ([]byte, error) { resp, err := http.Get(url) if err != nil { return []byte{0}, err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return []byte{0}, err } return body, nil }
EDIT: I'm looking for something like a Node module 'request' that allows me to do this on one line, for example: jsonStr, err: = getJsonStr (url).
source share