From a92e91da36b82435284f9075a52a9a2b059ea7a5 Mon Sep 17 00:00:00 2001 From: Will McCutchen Date: Mon, 17 Oct 2022 17:49:14 -0400 Subject: [PATCH] Drop usage of deprecated ioutil pkg --- httpbin/handlers_test.go | 14 +++++++------- httpbin/helpers.go | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go index 41b6e5d6..90c75fa8 100644 --- a/httpbin/handlers_test.go +++ b/httpbin/handlers_test.go @@ -9,7 +9,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "log" "math/rand" "mime/multipart" @@ -40,7 +40,7 @@ var app = New( WithDefaultParams(testDefaultParams), WithMaxBodySize(maxBodySize), WithMaxDuration(maxDuration), - WithObserver(StdLogObserver(log.New(ioutil.Discard, "", 0))), + WithObserver(StdLogObserver(log.New(io.Discard, "", 0))), ) var handler = app.Handler() @@ -1489,7 +1489,7 @@ func TestGzip(t *testing.T) { t.Fatalf("error creating gzip reader: %s", err) } - unzippedBody, err := ioutil.ReadAll(gzipReader) + unzippedBody, err := io.ReadAll(gzipReader) if err != nil { t.Fatalf("error reading gzipped body: %s", err) } @@ -1533,7 +1533,7 @@ func TestDeflate(t *testing.T) { if err != nil { t.Fatal(err) } - body, err := ioutil.ReadAll(reader) + body, err := io.ReadAll(reader) if err != nil { t.Fatal(err) } @@ -1805,7 +1805,7 @@ func TestDrip(t *testing.T) { } defer resp.Body.Close() - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) if err != nil { t.Fatalf("error reading response body: %s", err) } @@ -1829,7 +1829,7 @@ func TestDrip(t *testing.T) { } // in this case, the timeout happens while trying to read the body - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err == nil { t.Fatal("expected timeout reading body") } @@ -1892,7 +1892,7 @@ func TestDrip(t *testing.T) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("error reading response body: %s", err) } diff --git a/httpbin/helpers.go b/httpbin/helpers.go index e7157521..4b15e08d 100644 --- a/httpbin/helpers.go +++ b/httpbin/helpers.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/rand" "net/http" "net/url" @@ -109,7 +108,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error // Always set resp.Data to the incoming request body, in case we don't know // how to handle the content type - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { r.Body.Close() return err @@ -119,7 +118,7 @@ func parseBody(w http.ResponseWriter, r *http.Request, resp *bodyResponse) error // After reading the body to populate resp.Data, we need to re-wrap it in // an io.Reader for further processing below r.Body.Close() - r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + r.Body = io.NopCloser(bytes.NewBuffer(body)) ct := r.Header.Get("Content-Type") switch {