Skip to content

Commit

Permalink
Shore up HTTP client body closes, ioutil->io package
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed May 2, 2023
1 parent 07bc790 commit 3abd0dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/nano2nano/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"io"
stdlog "log"
"net/http"

Expand Down Expand Up @@ -119,7 +119,7 @@ func httpPut(client *http.Client, url string, key string, sendBytes []byte) erro
return err
}
defer res.Body.Close()
_, err = ioutil.ReadAll(res.Body)
_, err = io.ReadAll(res.Body)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions service/microwebhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func postWebhookEvent(
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("unexpected HTTP status %d %s", resp.StatusCode, resp.Status)
}
Expand Down
6 changes: 3 additions & 3 deletions service/nanomdm/dm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"

Expand Down Expand Up @@ -51,11 +51,11 @@ func (c *DeclarativeManagementHTTPCaller) DeclarativeManagement(r *mdm.Request,
if err != nil {
return nil, err
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return bodyBytes, service.NewHTTPStatusError(
resp.StatusCode,
Expand Down

0 comments on commit 3abd0dc

Please sign in to comment.