[go-nuts] if i catch resp.StatusCode != http.StatusOK and return early from my function, do i still have to close resp.Body??
Yes, always close the body in order to ensure the network connection is released. If you want to be able to reuse the connection, you should attempt to consume the body as well. -- 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.
[go-nuts] if i catch resp.StatusCode != http.StatusOK and return early from my function, do i still have to close resp.Body??
in the code snippet below which is inside a function, is "defer resp.Body.Close() " in the appropriate position? am i required to always do a resp.Body.Close()? ... resp, err := client.Do(req) log.Printf("resp: %+v\n", resp) if resp.StatusCode != http.StatusOK { return errors.NewHTTPError(resp.StatusCode) } defer resp.Body.Close() -- 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.