Skip to content

Commit

Permalink
Remove deprecated ioutil functions
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Feb 6, 2023
1 parent 436172e commit 05894c6
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 94 deletions.
5 changes: 2 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/imroc/req/v3/internal/util"
"golang.org/x/net/publicsuffix"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/cookiejar"
Expand Down Expand Up @@ -284,7 +283,7 @@ func (c *Client) SetRootCertFromString(pemContent string) *Client {
// SetRootCertsFromFile set root certificates from files.
func (c *Client) SetRootCertsFromFile(pemFiles ...string) *Client {
for _, pemFile := range pemFiles {
rootPemData, err := ioutil.ReadFile(pemFile)
rootPemData, err := os.ReadFile(pemFile)
if err != nil {
c.log.Errorf("failed to read root cert file: %v", err)
return c
Expand Down Expand Up @@ -1377,7 +1376,7 @@ func (c *Client) roundTrip(r *Request) (resp *Response, err error) {
if err == nil && !c.disableAutoReadResponse && !r.isSaveResponse && !r.disableAutoReadResponse {
_, err = resp.ToBytes()
// restore body for re-reads
resp.Body = ioutil.NopCloser(bytes.NewReader(resp.body))
resp.Body = io.NopCloser(bytes.NewReader(resp.body))
} else if err != nil {
resp.Err = err
}
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"github.com/imroc/req/v3/internal/header"
"github.com/imroc/req/v3/internal/tests"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -484,7 +484,7 @@ func testDisableAutoReadResponse(t *testing.T, c *Client) {

resp, err = c.R().Get("/")
assertSuccess(t, resp, err)
_, err = ioutil.ReadAll(resp.Body)
_, err = io.ReadAll(resp.Body)
tests.AssertNoError(t, err)
}

Expand Down
3 changes: 1 addition & 2 deletions examples/uploadcallback/uploadserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package main
import (
"github.com/gin-gonic/gin"
"io"
"io/ioutil"
"net/http"
)

func main() {
router := gin.Default()
router.POST("/upload", func(c *gin.Context) {
body := c.Request.Body
io.Copy(ioutil.Discard, body)
io.Copy(io.Discard, body)
c.String(http.StatusOK, "ok")
})
router.Run(":8888")
Expand Down
4 changes: 2 additions & 2 deletions internal/charsets/charsets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package charsets

import (
"github.com/imroc/req/v3/internal/tests"
"io/ioutil"
"os"
"runtime"
"testing"
)
Expand All @@ -30,7 +30,7 @@ func TestSniff(t *testing.T) {
}

for _, tc := range sniffTestCases {
content, err := ioutil.ReadFile(tests.GetTestFilePath(tc.filename))
content, err := os.ReadFile(tests.GetTestFilePath(tc.filename))
if err != nil {
t.Errorf("%s: error reading file: %v", tc.filename, err)
continue
Expand Down
5 changes: 2 additions & 3 deletions internal/http2/pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"testing"
)

Expand Down Expand Up @@ -85,7 +84,7 @@ func TestPipeCloseWithError(t *testing.T) {
io.WriteString(p, body)
a := errors.New("test error")
p.CloseWithError(a)
all, err := ioutil.ReadAll(p)
all, err := io.ReadAll(p)
if string(all) != body {
t.Errorf("read bytes = %q; want %q", all, body)
}
Expand All @@ -112,7 +111,7 @@ func TestPipeBreakWithError(t *testing.T) {
io.WriteString(p, "foo")
a := errors.New("test err")
p.BreakWithError(a)
all, err := ioutil.ReadAll(p)
all, err := io.ReadAll(p)
if string(all) != "" {
t.Errorf("read bytes = %q; want empty string", all)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/http2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"github.com/imroc/req/v3/internal/ascii"
"io"
"io/ioutil"
"log"
"math"
"net"
Expand Down Expand Up @@ -4707,7 +4706,7 @@ func stderrv() io.Writer {
return os.Stderr
}

return ioutil.Discard
return io.Discard
}

type safeBuffer struct {
Expand Down Expand Up @@ -4947,7 +4946,7 @@ func newServerTester(t testing.TB, handler http.HandlerFunc, opts ...interface{}

ts.TLS = ts.Config.TLSConfig // the httptest.Server has its own copy of this TLS config
if quiet {
ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
ts.Config.ErrorLog = log.New(io.Discard, "", 0)
} else {
ts.Config.ErrorLog = log.New(io.MultiWriter(stderrv(), twriter{t: t, st: st}, &st.serverLogBuf), "", log.LstdFlags)
}
Expand Down
Loading

0 comments on commit 05894c6

Please sign in to comment.