Open pellared opened 3 months ago
Might be related to https://github.com/timakin/bodyclose/issues/51
@timakin This is quite a big downside for other project adopt it. As per #50 I add a helper function:
// sneakyBodyClose closes the body and ignores the error.
// This is useful to close the HTTP response body when we don't care about the error.
func sneakyBodyClose(body io.ReadCloser) {
if body != nil {
_ = body.Close()
}
}
And now bodyclose cannot find defer sneakyBodyClose(resp.Body)
actually properly close the body.
I got a minor false positive for a deferred response close like below:
The workaround was to refactor to:
Tested with https://github.com/golangci/golangci-lint/releases/tag/v1.59.1 and https://github.com/open-telemetry/opentelemetry-go-contrib. PR for reference: https://github.com/open-telemetry/opentelemetry-go-contrib/pull/5962