Skip to content

Instantly share code, notes, and snippets.

@dividead
Created April 12, 2017 12:05
Show Gist options
  • Save dividead/d3c69b6773c5327507808cde43f10526 to your computer and use it in GitHub Desktop.
Save dividead/d3c69b6773c5327507808cde43f10526 to your computer and use it in GitHub Desktop.
func get(url string, acceptor interface{}) (interface{}, error) {
model := reflect.TypeOf(acceptor)
res, _ := http.Get(url)
defer res.Body.Close()
a := reflect.New(model).Interface()
buf, _ := ioutil.ReadAll(res.Body)
json.Unmarshal(buf, &a)
return a, nil
}
url := "https://api.github.com/users/urmom"
res, err := get(url, sometype)
x := res.(sometype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment