I noticed that in the golangci-lint
repo there's such a static check:
should check returned error before deferring response.Close
This means the following code will fail the lint check:
res, err := db.Conn.Query(ctx, query)
defer res.Close()
if err != nil {
return nil, err
}
However, I'm confused why the rule is like this. Shouldn't we close the response even when there's an error? Thus it makes more sense to me to defer the close before handling the error.