Skip to content

Instantly share code, notes, and snippets.

@chilts

chilts/gist:1158499

Created Aug 20, 2011
Embed
What would you like to do?
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