Created
August 20, 2011 02:05
-
-
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'
This file contains 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
// 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