Skip to content

Instantly share code, notes, and snippets.

@qassa
Created September 19, 2018 11:16
Show Gist options
  • Save qassa/b144d0d0d89c06ce13071f1983402d67 to your computer and use it in GitHub Desktop.
Save qassa/b144d0d0d89c06ce13071f1983402d67 to your computer and use it in GitHub Desktop.
Function in Go can return a function
func call(resp *http.Response) func() {
return func() {
if resp != nil {
resp.Body.Close()
}
}
}
func(url string) {
resp, err := http.Get(url)
body, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment