On Thu, Jul 28, 2016, at 03:14 PM, James Bardin wrote:
>
>
> On Thursday, July 28, 2016 at 2:40:38 AM UTC-4,
> krma...@gmail.com wrote:
>> resp, err := http.Get("https://api.ipify.org?format=json") if resp !=
>> nil { defer resp.Body.Close() }
>>
>
> This is incorrect. There's no guarantee that a non-nil Response
> contains a non-nil Body after an error.
>
>
>> 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 :-)
>
>
> No, this is correct "all of the time" , and is documented as such in
> the http package.
Is it? The http package only says:
"When err is nil, resp always contains a non-nil resp.Body. Caller
should close resp.Body when done reading from it."
It doesn't say anything about the case where err != nil
-- Ian
--
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.