From 9dc837e2c17f3556b29ea1d4825a82dd6d895299 Mon Sep 17 00:00:00 2001 From: Marco Franssen Date: Tue, 17 Sep 2024 15:07:19 +0200 Subject: [PATCH] Replace deprecated ioutil calls with io package --- .github/workflows/ci.yml | 2 +- go.mod | 2 +- middleware/compress.go | 5 ++--- middleware/compress_test.go | 3 +-- middleware/middleware_test.go | 5 ++--- middleware/throttle_test.go | 10 +++++----- middleware/wrap_writer.go | 3 +-- mux_test.go | 7 +++---- 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8f07b75..9215339a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: - go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x] + go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x] os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} diff --git a/go.mod b/go.mod index c084c1d5..5cd270cf 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/go-chi/chi/v5 -go 1.14 +go 1.16 diff --git a/middleware/compress.go b/middleware/compress.go index 28240c4b..9057feae 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "strings" @@ -160,12 +159,12 @@ func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { delete(c.encoders, encoding) // If the encoder supports Resetting (IoReseterWriter), then it can be pooled. - encoder := fn(ioutil.Discard, c.level) + encoder := fn(io.Discard, c.level) if encoder != nil { if _, ok := encoder.(ioResetterWriter); ok { pool := &sync.Pool{ New: func() interface{} { - return fn(ioutil.Discard, c.level) + return fn(io.Discard, c.level) }, } c.pooledEncoders[encoding] = pool diff --git a/middleware/compress_test.go b/middleware/compress_test.go index eaafc13b..496cda05 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -5,7 +5,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "strings" @@ -208,7 +207,7 @@ func decodeResponseBody(t *testing.T, resp *http.Response) string { default: reader = resp.Body } - respBody, err := ioutil.ReadAll(reader) + respBody, err := io.ReadAll(reader) if err != nil { t.Fatal(err) return "" diff --git a/middleware/middleware_test.go b/middleware/middleware_test.go index f7a626f4..760a19b9 100644 --- a/middleware/middleware_test.go +++ b/middleware/middleware_test.go @@ -3,7 +3,6 @@ package middleware import ( "crypto/tls" "io" - "io/ioutil" "net/http" "net/http/httptest" "path" @@ -93,7 +92,7 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io return nil, "" } - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) return nil, "" @@ -123,7 +122,7 @@ func testRequestNoRedirect(t *testing.T, ts *httptest.Server, method, path strin return nil, "" } - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) return nil, "" diff --git a/middleware/throttle_test.go b/middleware/throttle_test.go index 8ed7ff18..d57f144c 100644 --- a/middleware/throttle_test.go +++ b/middleware/throttle_test.go @@ -1,7 +1,7 @@ package middleware import ( - "io/ioutil" + "io" "net/http" "net/http/httptest" "strings" @@ -46,7 +46,7 @@ func TestThrottleBacklog(t *testing.T) { assertNoError(t, err) assertEqual(t, http.StatusOK, res.StatusCode) - buf, err := ioutil.ReadAll(res.Body) + buf, err := io.ReadAll(res.Body) assertNoError(t, err) assertEqual(t, testContent, buf) }(i) @@ -132,7 +132,7 @@ func TestThrottleTriggerGatewayTimeout(t *testing.T) { res, err := client.Get(server.URL) assertNoError(t, err) - buf, err := ioutil.ReadAll(res.Body) + buf, err := io.ReadAll(res.Body) assertNoError(t, err) assertEqual(t, http.StatusTooManyRequests, res.StatusCode) assertEqual(t, errTimedOut, strings.TrimSpace(string(buf))) @@ -172,7 +172,7 @@ func TestThrottleMaximum(t *testing.T) { assertNoError(t, err) assertEqual(t, http.StatusOK, res.StatusCode) - buf, err := ioutil.ReadAll(res.Body) + buf, err := io.ReadAll(res.Body) assertNoError(t, err) assertEqual(t, testContent, buf) @@ -192,7 +192,7 @@ func TestThrottleMaximum(t *testing.T) { res, err := client.Get(server.URL) assertNoError(t, err) - buf, err := ioutil.ReadAll(res.Body) + buf, err := io.ReadAll(res.Body) assertNoError(t, err) assertEqual(t, http.StatusTooManyRequests, res.StatusCode) assertEqual(t, errCapacityExceeded, strings.TrimSpace(string(buf))) diff --git a/middleware/wrap_writer.go b/middleware/wrap_writer.go index bf270881..670c48b4 100644 --- a/middleware/wrap_writer.go +++ b/middleware/wrap_writer.go @@ -6,7 +6,6 @@ package middleware import ( "bufio" "io" - "io/ioutil" "net" "net/http" ) @@ -104,7 +103,7 @@ func (b *basicWriter) Write(buf []byte) (n int, err error) { } else if b.tee != nil { n, err = b.tee.Write(buf) } else { - n, err = ioutil.Discard.Write(buf) + n, err = io.Discard.Write(buf) } b.bytes += n return n, err diff --git a/mux_test.go b/mux_test.go index 82f089e7..bb8fb304 100644 --- a/mux_test.go +++ b/mux_test.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "net/http" "net/http/httptest" @@ -186,7 +185,7 @@ func TestMuxBasic(t *testing.T) { t.Fatal(err) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) } @@ -1368,7 +1367,7 @@ func TestServeHTTPExistingContext(t *testing.T) { } req = req.WithContext(tc.Ctx) r.ServeHTTP(resp, req) - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("%v", err) } @@ -1855,7 +1854,7 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io return nil, "" } - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) return nil, ""