Skip to content

Commit a92e91d

Browse files
committed
Drop usage of deprecated ioutil pkg
1 parent e43229f commit a92e91d

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

httpbin/handlers_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"encoding/json"
1010
"errors"
1111
"fmt"
12-
"io/ioutil"
12+
"io"
1313
"log"
1414
"math/rand"
1515
"mime/multipart"
@@ -40,7 +40,7 @@ var app = New(
4040
WithDefaultParams(testDefaultParams),
4141
WithMaxBodySize(maxBodySize),
4242
WithMaxDuration(maxDuration),
43-
WithObserver(StdLogObserver(log.New(ioutil.Discard, "", 0))),
43+
WithObserver(StdLogObserver(log.New(io.Discard, "", 0))),
4444
)
4545

4646
var handler = app.Handler()
@@ -1489,7 +1489,7 @@ func TestGzip(t *testing.T) {
14891489
t.Fatalf("error creating gzip reader: %s", err)
14901490
}
14911491

1492-
unzippedBody, err := ioutil.ReadAll(gzipReader)
1492+
unzippedBody, err := io.ReadAll(gzipReader)
14931493
if err != nil {
14941494
t.Fatalf("error reading gzipped body: %s", err)
14951495
}
@@ -1533,7 +1533,7 @@ func TestDeflate(t *testing.T) {
15331533
if err != nil {
15341534
t.Fatal(err)
15351535
}
1536-
body, err := ioutil.ReadAll(reader)
1536+
body, err := io.ReadAll(reader)
15371537
if err != nil {
15381538
t.Fatal(err)
15391539
}
@@ -1805,7 +1805,7 @@ func TestDrip(t *testing.T) {
18051805
}
18061806
defer resp.Body.Close()
18071807

1808-
body, _ := ioutil.ReadAll(resp.Body)
1808+
body, _ := io.ReadAll(resp.Body)
18091809
if err != nil {
18101810
t.Fatalf("error reading response body: %s", err)
18111811
}
@@ -1829,7 +1829,7 @@ func TestDrip(t *testing.T) {
18291829
}
18301830

18311831
// in this case, the timeout happens while trying to read the body
1832-
body, err := ioutil.ReadAll(resp.Body)
1832+
body, err := io.ReadAll(resp.Body)
18331833
if err == nil {
18341834
t.Fatal("expected timeout reading body")
18351835
}
@@ -1892,7 +1892,7 @@ func TestDrip(t *testing.T) {
18921892
}
18931893
defer resp.Body.Close()
18941894

1895-
body, err := ioutil.ReadAll(resp.Body)
1895+
body, err := io.ReadAll(resp.Body)
18961896
if err != nil {
18971897
t.Fatalf("error reading response body: %s", err)
18981898
}

httpbin/helpers.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"math/rand"
1312
"net/http"
1413
"net/url"
@@ -109,7 +108,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
109108

110109
// Always set resp.Data to the incoming request body, in case we don't know
111110
// how to handle the content type
112-
body, err := ioutil.ReadAll(r.Body)
111+
body, err := io.ReadAll(r.Body)
113112
if err != nil {
114113
r.Body.Close()
115114
return err
@@ -119,7 +118,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error
119118
// After reading the body to populate resp.Data, we need to re-wrap it in
120119
// an io.Reader for further processing below
121120
r.Body.Close()
122-
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
121+
r.Body = io.NopCloser(bytes.NewBuffer(body))
123122

124123
ct := r.Header.Get("Content-Type")
125124
switch {

0 commit comments

Comments
 (0)