Skip to content

Commit

Permalink
Merge pull request #238 from Scalingo/fix/ioutil_deprecation
Browse files Browse the repository at this point in the history
refactor: replace use of the deprecated ioutil package
  • Loading branch information
EtienneM authored Nov 17, 2021
2 parents 34d93b1 + 1515f00 commit 3d04842
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## To Be Released

* refactor: replace use of the deprecated ioutil package [#238](https://github.com/Scalingo/go-scalingo/pull/238)

## 4.15.1

* chore: generate missing mocks from v4.15.0
Expand Down
8 changes: 4 additions & 4 deletions addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package scalingo

import (
"encoding/json"
"io/ioutil"
"io"
"strconv"
"time"

"github.com/Scalingo/go-scalingo/v4/http"

"gopkg.in/errgo.v1"

"github.com/Scalingo/go-scalingo/v4/http"
)

type AddonsService interface {
Expand Down Expand Up @@ -169,7 +169,7 @@ func (c *Client) AddonLogsArchives(app, addonID string, page int) (*LogsArchives
return nil, errgo.Notef(err, "fail to get log archives")
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errgo.Notef(err, "fail to read body of response")
}
Expand Down
9 changes: 5 additions & 4 deletions auth_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package scalingo
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/golang/mock/gomock"

httpclient "github.com/Scalingo/go-scalingo/v4/http"
"github.com/Scalingo/go-scalingo/v4/http/httpmock"
jwt "github.com/golang-jwt/jwt/v4"
gomock "github.com/golang/mock/gomock"
)

func MockAuth(ctrl *gomock.Controller) *httpmock.MockClient {
Expand All @@ -27,7 +28,7 @@ func MockAuth(ctrl *gomock.Controller) *httpmock.MockClient {
}

return &http.Response{
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(fmt.Sprintf(`{"token": "%v"}`, jwt)))),
Body: io.NopCloser(bytes.NewBuffer([]byte(fmt.Sprintf(`{"token": "%v"}`, jwt)))),
}, nil
}).AnyTimes()
return mock
Expand Down
5 changes: 2 additions & 3 deletions http/api_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"reflect"
Expand Down Expand Up @@ -126,7 +125,7 @@ func (c *client) Do(req *APIRequest) (*http.Response, error) {
return nil, fmt.Errorf("Fail to query %s: %v", req.HTTPRequest.Host, err)
}
debug.Printf(pkgio.Indent("Request ID: %v", 6), res.Header.Get("X-Request-Id"))
debug.Printf(pkgio.Indent("Duration: %v", 6), time.Now().Sub(now))
debug.Printf(pkgio.Indent("Duration: %v", 6), time.Since(now))

if req.Expected.Contains(res.StatusCode) {
return res, nil
Expand All @@ -145,7 +144,7 @@ func (c *client) doRequest(req *http.Request) (*http.Response, error) {
}

func parseJSON(res *http.Response, data interface{}) error {
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
reqErr := fmt.Sprintf("%v %v", res.Request.Method, res.Request.URL)
return errgo.Newf("fail to read body of request %v: %v", reqErr, err)
Expand Down
6 changes: 3 additions & 3 deletions logs-archives.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scalingo

import (
"encoding/json"
"io/ioutil"
"io"
"strconv"

"gopkg.in/errgo.v1"
Expand Down Expand Up @@ -43,7 +43,7 @@ func (c *Client) LogsArchivesByCursor(app string, cursor string) (*LogsArchivesR
return nil, errgo.Mask(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errgo.Mask(err)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (c *Client) LogsArchives(app string, page int) (*LogsArchivesResponse, erro
return nil, errgo.Mask(err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errgo.Mask(err)
}
Expand Down

0 comments on commit 3d04842

Please sign in to comment.