http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/index.html#close_http_resp_body


Recommends the below.
I wanted to confirm with golang people if this is indeed the correct 
approach. Can the response be not nil in cases where there is an error ?

resp, err := http.Get("https://api.ipify.org?format=json";) if resp != nil { 
defer resp.Body.Close() }


Vs

resp, err := http.Get("https://api.ipify.org?format=json";) if err != nil { 
fmt.Println(err) return } defer resp.Body.Close()//ok, most of the time :-)

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to