Skip to content

Commit

Permalink
Check error returned for Body.Close in defer
Browse files Browse the repository at this point in the history
This resolves a lint error
  • Loading branch information
mhutchinson committed Apr 15, 2024
1 parent a722ddb commit 314feca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v3.7.1
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.55.0
version: v1.57.2
args: --timeout 5m
8 changes: 7 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/url"
"strconv"

"github.com/golang/glog"
"github.com/transparency-dev/distributor/api"
)

Expand Down Expand Up @@ -104,7 +105,12 @@ func (d *RestDistributor) fetchData(u *url.URL) ([]byte, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() {
if err := resp.Body.Close(); err != nil {
glog.Errorf("Failed to close body: %v", err)
}
}()

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read body: %v", err)
Expand Down

0 comments on commit 314feca

Please sign in to comment.