FAQ
Hi

Wanted to gain better understanding of this. The recommendation I see about
closing http response body always comes with a "defer". I wanted to
understand if it's required to defer closing http response body always or
is it alright if it's closed once you are done with it, for example,
body, err := ioutil.ReadAll(res.Body)
if err!= nil{
    //handle error
    //return
}
res.Body.Close()

Why is a 'defer'ed closure recommended always?

Thank you
Neelesh

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 11, '16 at 12:27a
activeMay 11, '16 at 10:50a
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase