Skip to content

Instantly share code, notes, and snippets.

@lucindo
Last active August 29, 2015 13:57
Show Gist options
  • Save lucindo/9856743 to your computer and use it in GitHub Desktop.
Save lucindo/9856743 to your computer and use it in GitHub Desktop.
package netutil
import (
"encoding/json"
"io/ioutil"
"net/http"
)
func GetURLContents(url string) (contents []byte, err error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
contents, err = ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return
}
func RemoteUnmarshal(url string, response interface{}) error {
contents, err := GetURLContents(url)
if err != nil {
return err
}
if err = json.Unmarshal(contents, &response); err != nil {
return err
}
return nil
}
@lucindo
Copy link
Author

lucindo commented Mar 29, 2014

@trajber critique, please...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment