Skip to content

Instantly share code, notes, and snippets.

@chilts
Created August 20, 2011 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilts/1158499 to your computer and use it in GitHub Desktop.
Save chilts/1158499 to your computer and use it in GitHub Desktop.
Instead of passing 'r' and calling r.Body.Close() in some other function, just use 'defer'
// Current Code
r, err := http.DefaultClient.Do(&req)
if err != nil {
return nil, err
}
function_dowork_that_also_calls_r_body_close(r)
// My Thoughts
r, err := http.DefaultClient.Do(&req)
defer r.Body.Close()
if err != nil {
return nil, err
}
function_dowork(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment