3 ms·
defer resp.Body.Close() That's almost a proverb by itself.
by buro9 11y ago
defer resp.Body.Close()
That's almost a proverb by itself.
- omginternets 11y agoSince you mention it: when is it necessary to close the response body?
- deleted 11y ago[deleted]
- buro9 11y agoAny time you managed to get a response you must close the body via a defer resp.Body.Close() And if you're using json.Decoder on the response body then it's worth noting that if you know you're only receiving a single JSON object then draining the remainder of the body will allow connection re-use as otherwise the connection will be closed and not re-used: https://github.com/google/go-github/commit/e0ff7111b024fda991e457d975e0b73e1380f05f https://github.com/google/go-github/commit/e0ff7111b024fda99...
- omginternets 11y agoEven if I don't read the body?
- buro9 11y agoEven if you don't read the body.