Always defer http.Response.Body.Close()
This is something that most of the new Golang developers always forgot, remember you must close the Response.Body after use, to avoid forgot this you can defer the Close and it will be executed at the finish of the function.
Ex:
func someAwesomeFunc(param string) {
//Lot of stuff
resp, err := http.Get(URL.String())
defer resp.Body.Close()
//lot of stuff including resp
//close will be executed here
}
Written by Christopher Herrera
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Go
Authors
Related Tags
#go
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#