Last active
August 29, 2015 13:57
-
-
Save lucindo/9856743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@trajber critique, please...