diff --git a/.golangci.yml b/.golangci.yml index 4cd6d42..824667f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,7 +27,7 @@ linters-settings: linters: enable: - megacheck - - golint + - revive - govet - unconvert - megacheck diff --git a/basic_auth_test.go b/basic_auth_test.go index 247533a..160dcef 100644 --- a/basic_auth_test.go +++ b/basic_auth_test.go @@ -25,7 +25,7 @@ func TestBasicAuth(t *testing.T) { client := http.Client{Timeout: 5 * time.Second} { - req, err := http.NewRequest("GET", u, nil) + req, err := http.NewRequest("GET", u, http.NoBody) require.NoError(t, err) resp, err := client.Do(req) require.NoError(t, err) @@ -33,7 +33,7 @@ func TestBasicAuth(t *testing.T) { } { - req, err := http.NewRequest("GET", u, nil) + req, err := http.NewRequest("GET", u, http.NoBody) require.NoError(t, err) req.SetBasicAuth("dev", "good") resp, err := client.Do(req) @@ -42,7 +42,7 @@ func TestBasicAuth(t *testing.T) { } { - req, err := http.NewRequest("GET", u, nil) + req, err := http.NewRequest("GET", u, http.NoBody) require.NoError(t, err) req.SetBasicAuth("dev", "bad") resp, err := client.Do(req) diff --git a/blackwords.go b/blackwords.go index 08f1c64..dd120d7 100644 --- a/blackwords.go +++ b/blackwords.go @@ -2,7 +2,7 @@ package rest import ( "bytes" - "io/ioutil" + "io" "net/http" "strings" ) @@ -13,9 +13,9 @@ func BlackWords(words ...string) func(http.Handler) http.Handler { return func(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { - if content, err := ioutil.ReadAll(r.Body); err == nil { + if content, err := io.ReadAll(r.Body); err == nil { body := strings.ToLower(string(content)) - r.Body = ioutil.NopCloser(bytes.NewReader(content)) + r.Body = io.NopCloser(bytes.NewReader(content)) if len(body) > 0 { for _, word := range words { diff --git a/depricattion.go b/depricattion.go index 7b5f713..ded640b 100644 --- a/depricattion.go +++ b/depricattion.go @@ -11,7 +11,7 @@ import ( func Deprecation(version string, date time.Time) func(http.Handler) http.Handler { f := func(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { - headerVal := fmt.Sprintf("version=\"%s\", date=\"%s\"", version, date.Format(time.RFC3339)) + headerVal := fmt.Sprintf("version=%q, date=%q", version, date.Format(time.RFC3339)) w.Header().Set("Deprecation", headerVal) h.ServeHTTP(w, r) } diff --git a/depricattion_test.go b/depricattion_test.go index c9afcdb..b245399 100644 --- a/depricattion_test.go +++ b/depricattion_test.go @@ -19,7 +19,7 @@ func TestDeprecated(t *testing.T) { u := fmt.Sprintf("%s%s", ts.URL, "/something") client := http.Client{Timeout: 5 * time.Second} - req, err := http.NewRequest("GET", u, nil) + req, err := http.NewRequest("GET", u, http.NoBody) require.NoError(t, err) r, err := client.Do(req) diff --git a/file_server.go b/file_server.go index 1bed799..49b67d8 100644 --- a/file_server.go +++ b/file_server.go @@ -3,7 +3,6 @@ package rest import ( "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -172,7 +171,7 @@ func custom404Handler(next http.Handler, notFound io.Reader) (http.Handler, erro return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { next.ServeHTTP(w, r) }), nil } - body, err := ioutil.ReadAll(notFound) + body, err := io.ReadAll(notFound) if err != nil { return nil, err } diff --git a/file_server_test.go b/file_server_test.go index 703f0e1..1d7e19e 100644 --- a/file_server_test.go +++ b/file_server_test.go @@ -2,7 +2,7 @@ package rest import ( "bytes" - "io/ioutil" + "io" "net/http" "net/http/httptest" "strconv" @@ -56,19 +56,19 @@ func TestFileServerDefault(t *testing.T) { tt := tt t.Run(strconv.Itoa(i), func(t *testing.T) { for _, ts := range []*httptest.Server{ts1, ts2} { - req, err := http.NewRequest("GET", ts.URL+tt.req, nil) + req, err := http.NewRequest("GET", ts.URL+tt.req, http.NoBody) require.NoError(t, err) resp, err := client.Do(req) require.NoError(t, err) t.Logf("headers: %v", resp.Header) assert.Equal(t, tt.status, resp.StatusCode) if resp.StatusCode == http.StatusNotFound { - msg, e := ioutil.ReadAll(resp.Body) + msg, e := io.ReadAll(resp.Body) require.NoError(t, e) assert.Equal(t, "404 page not found\n", string(msg)) return } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) require.NoError(t, err) assert.Equal(t, tt.body, string(body)) } @@ -84,12 +84,12 @@ func TestFileServerWithListing(t *testing.T) { client := http.Client{Timeout: 599 * time.Second} { - req, err := http.NewRequest("GET", ts.URL+"/static/1", nil) + req, err := http.NewRequest("GET", ts.URL+"/static/1", http.NoBody) require.NoError(t, err) resp, err := client.Do(req) require.NoError(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) - msg, err := ioutil.ReadAll(resp.Body) + msg, err := io.ReadAll(resp.Body) require.NoError(t, err) exp := `
 f1.html
@@ -100,18 +100,18 @@ func TestFileServerWithListing(t *testing.T) {
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/static/xyz.js", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/static/xyz.js", http.NoBody)
 		require.NoError(t, err)
 		resp, err := client.Do(req)
 		require.NoError(t, err)
 		assert.Equal(t, http.StatusOK, resp.StatusCode)
-		msg, err := ioutil.ReadAll(resp.Body)
+		msg, err := io.ReadAll(resp.Body)
 		require.NoError(t, err)
 		assert.Equal(t, "testdata/xyz.js", string(msg))
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/static/no-such-thing.html", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/static/no-such-thing.html", http.NoBody)
 		require.NoError(t, err)
 		resp, err := client.Do(req)
 		require.NoError(t, err)
@@ -128,45 +128,45 @@ func TestFileServer_Custom404(t *testing.T) {
 	client := http.Client{Timeout: 599 * time.Second}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/static/xyz.js", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/static/xyz.js", http.NoBody)
 		require.NoError(t, err)
 		resp, err := client.Do(req)
 		require.NoError(t, err)
 		assert.Equal(t, http.StatusOK, resp.StatusCode)
-		msg, err := ioutil.ReadAll(resp.Body)
+		msg, err := io.ReadAll(resp.Body)
 		require.NoError(t, err)
 		assert.Equal(t, "testdata/xyz.js", string(msg))
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/static/nofile.js", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/static/nofile.js", http.NoBody)
 		require.NoError(t, err)
 		resp, err := client.Do(req)
 		require.NoError(t, err)
 		assert.Equal(t, http.StatusNotFound, resp.StatusCode)
-		msg, err := ioutil.ReadAll(resp.Body)
+		msg, err := io.ReadAll(resp.Body)
 		require.NoError(t, err)
 		assert.Equal(t, "custom 404", string(msg))
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/xyz.html", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/xyz.html", http.NoBody)
 		require.NoError(t, err)
 		resp, err := client.Do(req)
 		require.NoError(t, err)
 		assert.Equal(t, http.StatusNotFound, resp.StatusCode)
-		msg, err := ioutil.ReadAll(resp.Body)
+		msg, err := io.ReadAll(resp.Body)
 		require.NoError(t, err)
 		assert.Equal(t, "custom 404", string(msg))
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/static/xyz.js", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/static/xyz.js", http.NoBody)
 		require.NoError(t, err)
 		resp, err := client.Do(req)
 		require.NoError(t, err)
 		assert.Equal(t, http.StatusOK, resp.StatusCode)
-		msg, err := ioutil.ReadAll(resp.Body)
+		msg, err := io.ReadAll(resp.Body)
 		require.NoError(t, err)
 		assert.Equal(t, "testdata/xyz.js", string(msg))
 	}
@@ -213,19 +213,19 @@ func TestFileServerSPA(t *testing.T) {
 		tt := tt
 		t.Run(strconv.Itoa(i), func(t *testing.T) {
 			for _, ts := range []*httptest.Server{ts1, ts2} {
-				req, err := http.NewRequest("GET", ts.URL+tt.req, nil)
+				req, err := http.NewRequest("GET", ts.URL+tt.req, http.NoBody)
 				require.NoError(t, err)
 				resp, err := client.Do(req)
 				require.NoError(t, err)
 				t.Logf("headers: %v", resp.Header)
 				assert.Equal(t, tt.status, resp.StatusCode)
 				if resp.StatusCode == http.StatusNotFound {
-					msg, e := ioutil.ReadAll(resp.Body)
+					msg, e := io.ReadAll(resp.Body)
 					require.NoError(t, e)
 					assert.Equal(t, "404 page not found\n", string(msg))
 					return
 				}
-				body, err := ioutil.ReadAll(resp.Body)
+				body, err := io.ReadAll(resp.Body)
 				require.NoError(t, err)
 				assert.Equal(t, tt.body, string(body))
 			}
diff --git a/go.mod b/go.mod
index 7898921..5a64a6d 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module github.com/go-pkgz/rest
 
-go 1.15
+go 1.16
 
 require (
 	github.com/pkg/errors v0.9.1
diff --git a/go.sum b/go.sum
index 0caa82c..22c86e5 100644
--- a/go.sum
+++ b/go.sum
@@ -4,10 +4,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
-github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
diff --git a/gzip.go b/gzip.go
index c5e77c9..a7328b0 100644
--- a/gzip.go
+++ b/gzip.go
@@ -3,7 +3,6 @@ package rest
 import (
 	"compress/gzip"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"strings"
 	"sync"
@@ -21,7 +20,7 @@ var gzDefaultContentTypes = []string{
 }
 
 var gzPool = sync.Pool{
-	New: func() interface{} { return gzip.NewWriter(ioutil.Discard) },
+	New: func() interface{} { return gzip.NewWriter(io.Discard) },
 }
 
 type gzipResponseWriter struct {
diff --git a/gzip_test.go b/gzip_test.go
index b283cac..8532624 100644
--- a/gzip_test.go
+++ b/gzip_test.go
@@ -3,7 +3,7 @@ package rest
 import (
 	"bytes"
 	"compress/gzip"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"strings"
@@ -29,7 +29,7 @@ func TestGzipCustom(t *testing.T) {
 	client := http.Client{}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/something", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/something", http.NoBody)
 		require.NoError(t, err)
 		req.Header.Set("Accept-Encoding", "gzip")
 		req.Header.Set("Content-Type", "text/plain; charset=utf-8")
@@ -37,19 +37,19 @@ func TestGzipCustom(t *testing.T) {
 		require.NoError(t, err)
 		assert.Equal(t, 200, resp.StatusCode)
 		defer resp.Body.Close()
-		b, err := ioutil.ReadAll(resp.Body)
+		b, err := io.ReadAll(resp.Body)
 		assert.NoError(t, err)
 		assert.Equal(t, 357, len(b), "compressed size")
 
 		gzr, err := gzip.NewReader(bytes.NewBuffer(b))
 		require.NoError(t, err)
-		b, err = ioutil.ReadAll(gzr)
+		b, err = io.ReadAll(gzr)
 		require.NoError(t, err)
 		assert.True(t, strings.HasPrefix(string(b), "Lorem Ipsum"), string(b))
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/something", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/something", http.NoBody)
 		require.NoError(t, err)
 		req.Header.Set("Accept-Encoding", "gzip")
 		req.Header.Set("Content-Type", "something")
@@ -57,7 +57,7 @@ func TestGzipCustom(t *testing.T) {
 		require.NoError(t, err)
 		assert.Equal(t, 200, resp.StatusCode)
 		defer resp.Body.Close()
-		b, err := ioutil.ReadAll(resp.Body)
+		b, err := io.ReadAll(resp.Body)
 		assert.NoError(t, err)
 		assert.Equal(t, 576, len(b), "uncompressed size")
 	}
@@ -80,7 +80,7 @@ func TestGzipDefault(t *testing.T) {
 	client := http.Client{}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/something", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/something", http.NoBody)
 		require.NoError(t, err)
 		req.Header.Set("Accept-Encoding", "gzip")
 		req.Header.Set("Content-Type", "text/plain")
@@ -88,31 +88,31 @@ func TestGzipDefault(t *testing.T) {
 		require.NoError(t, err)
 		assert.Equal(t, 200, resp.StatusCode)
 		defer resp.Body.Close()
-		b, err := ioutil.ReadAll(resp.Body)
+		b, err := io.ReadAll(resp.Body)
 		assert.NoError(t, err)
 		assert.Equal(t, 357, len(b), "compressed size")
 
 		gzr, err := gzip.NewReader(bytes.NewBuffer(b))
 		require.NoError(t, err)
-		b, err = ioutil.ReadAll(gzr)
+		b, err = io.ReadAll(gzr)
 		require.NoError(t, err)
 		assert.True(t, strings.HasPrefix(string(b), "Lorem Ipsum"), string(b))
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/something", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/something", http.NoBody)
 		require.NoError(t, err)
 		resp, err := client.Do(req)
 		require.Nil(t, err)
 		assert.Equal(t, 200, resp.StatusCode)
 		defer resp.Body.Close()
-		b, err := ioutil.ReadAll(resp.Body)
+		b, err := io.ReadAll(resp.Body)
 		assert.NoError(t, err)
 		assert.Equal(t, 576, len(b), "uncompressed size")
 	}
 
 	{
-		req, err := http.NewRequest("GET", ts.URL+"/something", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/something", http.NoBody)
 		require.NoError(t, err)
 		req.Header.Set("Accept-Encoding", "gzip")
 		req.Header.Set("Content-Type", "something")
@@ -120,7 +120,7 @@ func TestGzipDefault(t *testing.T) {
 		require.NoError(t, err)
 		assert.Equal(t, 200, resp.StatusCode)
 		defer resp.Body.Close()
-		b, err := ioutil.ReadAll(resp.Body)
+		b, err := io.ReadAll(resp.Body)
 		assert.NoError(t, err)
 		assert.Equal(t, 576, len(b), "uncompressed size")
 	}
diff --git a/httperrors_test.go b/httperrors_test.go
index ee4408c..618f2bb 100644
--- a/httperrors_test.go
+++ b/httperrors_test.go
@@ -2,7 +2,7 @@ package rest
 
 import (
 	"errors"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"testing"
@@ -27,7 +27,7 @@ func TestSendErrorJSON(t *testing.T) {
 	require.Nil(t, err)
 	defer resp.Body.Close()
 
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	require.Nil(t, err)
 	assert.Equal(t, 500, resp.StatusCode)
 	assert.Equal(t, "application/json; charset=utf-8", resp.Header.Get("content-type"))
@@ -37,7 +37,7 @@ func TestSendErrorJSON(t *testing.T) {
 
 func TestErrorDetailsMsg(t *testing.T) {
 	callerFn := func() {
-		req, err := http.NewRequest("GET", "https://example.com/test?k1=v1&k2=v2", nil)
+		req, err := http.NewRequest("GET", "https://example.com/test?k1=v1&k2=v2", http.NoBody)
 		require.Nil(t, err)
 		req.RemoteAddr = "1.2.3.4"
 		msg := errDetailsMsg(req, 500, errors.New("error 500"), "error details 123456")
@@ -51,7 +51,7 @@ func TestErrorDetailsMsg(t *testing.T) {
 
 func TestErrorDetailsMsgNoError(t *testing.T) {
 	callerFn := func() {
-		req, err := http.NewRequest("GET", "https://example.com/test?k1=v1&k2=v2", nil)
+		req, err := http.NewRequest("GET", "https://example.com/test?k1=v1&k2=v2", http.NoBody)
 		require.Nil(t, err)
 		req.RemoteAddr = "1.2.3.4"
 		msg := errDetailsMsg(req, 500, nil, "error details 123456")
@@ -78,7 +78,7 @@ func TestErrorLogger_Log(t *testing.T) {
 	require.Nil(t, err)
 	defer resp.Body.Close()
 
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	require.Nil(t, err)
 	assert.Equal(t, 500, resp.StatusCode)
 
diff --git a/logger/logger.go b/logger/logger.go
index a95d592..cc7d9e5 100644
--- a/logger/logger.go
+++ b/logger/logger.go
@@ -6,7 +6,6 @@ import (
 	"bytes"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"log"
 	"net"
 	"net/http"
@@ -220,7 +219,7 @@ func (l *Middleware) getBody(r *http.Request) string {
 	// Note that below assignment is not approved by the docs:
 	// "Except for reading the body, handlers should not modify the provided Request."
 	// https://golang.org/pkg/net/http/#Handler
-	r.Body = ioutil.NopCloser(reader)
+	r.Body = io.NopCloser(reader)
 
 	if len(body) > 0 {
 		body = strings.Replace(body, "\n", " ", -1)
diff --git a/logger/logger_test.go b/logger/logger_test.go
index 869c8d6..46c1727 100644
--- a/logger/logger_test.go
+++ b/logger/logger_test.go
@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"errors"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"net/url"
@@ -33,7 +33,7 @@ func TestLoggerMinimal(t *testing.T) {
 	require.Nil(t, err)
 	defer resp.Body.Close()
 	assert.Equal(t, 200, resp.StatusCode)
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 
@@ -64,7 +64,7 @@ func TestLoggerMinimalLocalhost(t *testing.T) {
 	require.Nil(t, err)
 	defer resp.Body.Close()
 	assert.Equal(t, 200, resp.StatusCode)
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 
@@ -104,7 +104,7 @@ func TestLogger(t *testing.T) {
 	require.Nil(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 
@@ -128,7 +128,7 @@ func TestLoggerIP(t *testing.T) {
 
 	clint := http.Client{}
 
-	req, err := http.NewRequest("GET", ts.URL+"/blah", nil)
+	req, err := http.NewRequest("GET", ts.URL+"/blah", http.NoBody)
 	require.NoError(t, err)
 	resp, err := clint.Do(req)
 	require.Nil(t, err)
@@ -138,7 +138,7 @@ func TestLoggerIP(t *testing.T) {
 	assert.True(t, strings.Contains(s, "- 127.0.0.1!masked -"))
 
 	lb.buf.Reset()
-	req, err = http.NewRequest("GET", ts.URL+"/blah", nil)
+	req, err = http.NewRequest("GET", ts.URL+"/blah", http.NoBody)
 	require.NoError(t, err)
 	req.Header.Set("X-Forwarded-For", "1.2.3.4")
 	resp, err = clint.Do(req)
@@ -173,7 +173,7 @@ func TestLoggerTraceID(t *testing.T) {
 	defer ts.Close()
 
 	clint := http.Client{}
-	req, err := http.NewRequest("GET", ts.URL+"/blah", nil)
+	req, err := http.NewRequest("GET", ts.URL+"/blah", http.NoBody)
 	require.NoError(t, err)
 	req.Header.Set("X-Request-ID", "0000-reqid")
 	resp, err := clint.Do(req)
@@ -198,7 +198,7 @@ func TestLoggerTraceID(t *testing.T) {
 func TestLoggerMaxBodySize(t *testing.T) {
 
 	handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		body, err := ioutil.ReadAll(r.Body)
+		body, err := io.ReadAll(r.Body)
 		assert.NoError(t, err)
 		assert.Equal(t, "1234567890 abcdefg", string(body))
 		_, err = w.Write([]byte("blah blah"))
@@ -215,7 +215,7 @@ func TestLoggerMaxBodySize(t *testing.T) {
 	require.Nil(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 
@@ -238,7 +238,7 @@ func TestLoggerDefault(t *testing.T) {
 	require.Nil(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 }
@@ -287,7 +287,7 @@ func TestPeek(t *testing.T) {
 		if !assert.NoError(t, err) {
 			continue
 		}
-		body, err := ioutil.ReadAll(r)
+		body, err := io.ReadAll(r)
 		if !assert.NoError(t, err) {
 			continue
 		}
@@ -361,7 +361,7 @@ func TestLoggerApacheCombined(t *testing.T) {
 	require.Nil(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 
diff --git a/metrics_test.go b/metrics_test.go
index 788c456..7851f3d 100644
--- a/metrics_test.go
+++ b/metrics_test.go
@@ -1,7 +1,7 @@
 package rest
 
 import (
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"strings"
@@ -24,7 +24,7 @@ func TestMetrics(t *testing.T) {
 	defer resp.Body.Close()
 	assert.Equal(t, 200, resp.StatusCode)
 
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.True(t, strings.Contains(string(b), "cmdline"))
 	assert.True(t, strings.Contains(string(b), "memstats"))
diff --git a/middleware_test.go b/middleware_test.go
index b047a2f..9601b77 100644
--- a/middleware_test.go
+++ b/middleware_test.go
@@ -3,7 +3,7 @@ package rest
 import (
 	"bytes"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"os"
@@ -30,7 +30,7 @@ func TestMiddleware_AppInfo(t *testing.T) {
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
 
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 
 	assert.Equal(t, "blah blah", string(b))
@@ -53,7 +53,7 @@ func TestMiddleware_Ping(t *testing.T) {
 	require.Nil(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "pong", string(b))
 
@@ -61,7 +61,7 @@ func TestMiddleware_Ping(t *testing.T) {
 	require.Nil(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
-	b, err = ioutil.ReadAll(resp.Body)
+	b, err = io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 }
@@ -94,7 +94,7 @@ func TestMiddleware_Recoverer(t *testing.T) {
 	require.NoError(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	defer resp.Body.Close()
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 }
diff --git a/nocache_test.go b/nocache_test.go
index cf68d03..471fbd5 100644
--- a/nocache_test.go
+++ b/nocache_test.go
@@ -17,7 +17,7 @@ func TestNoCache(t *testing.T) {
 	})
 
 	handler := NoCache(testHandler)
-	req, err := http.NewRequest("GET", "/api/v1/params", nil)
+	req, err := http.NewRequest("GET", "/api/v1/params", http.NoBody)
 	require.NoError(t, err)
 	req.Header.Set("ETag", "123")
 	req.Header.Set("If-None-Match", "xyz")
diff --git a/onlyfrom_test.go b/onlyfrom_test.go
index 904d56e..279e5ba 100644
--- a/onlyfrom_test.go
+++ b/onlyfrom_test.go
@@ -1,7 +1,7 @@
 package rest
 
 import (
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"testing"
@@ -24,7 +24,7 @@ func TestOnlyFromAllowed(t *testing.T) {
 	defer resp.Body.Close()
 	assert.Equal(t, 200, resp.StatusCode)
 
-	b, err := ioutil.ReadAll(resp.Body)
+	b, err := io.ReadAll(resp.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, "blah blah", string(b))
 }
@@ -39,7 +39,7 @@ func TestOnlyFromAllowedHeaders(t *testing.T) {
 	defer ts.Close()
 
 	reqWithHeader := func(header string) (*http.Request, error) {
-		req, err := http.NewRequest("GET", ts.URL+"/blah", nil)
+		req, err := http.NewRequest("GET", ts.URL+"/blah", http.NoBody)
 		if err != nil {
 			return nil, err
 		}
@@ -80,7 +80,7 @@ func TestOnlyFromAllowedCIDR(t *testing.T) {
 	defer ts.Close()
 
 	client := http.Client{}
-	req, err := http.NewRequest("GET", ts.URL+"/blah", nil)
+	req, err := http.NewRequest("GET", ts.URL+"/blah", http.NoBody)
 	require.NoError(t, err)
 	req.Header.Set("X-Real-IP", "1.1.1.1")
 	resp, err := client.Do(req)
diff --git a/rest_test.go b/rest_test.go
index e9a2dc2..4aefcd5 100644
--- a/rest_test.go
+++ b/rest_test.go
@@ -2,7 +2,7 @@ package rest
 
 import (
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"testing"
@@ -23,7 +23,7 @@ func TestRest_RenderJSON(t *testing.T) {
 	require.NoError(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
 	require.NoError(t, err)
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	require.NoError(t, err)
 	defer resp.Body.Close()
 
@@ -41,7 +41,7 @@ func TestRest_RenderJSONFromBytes(t *testing.T) {
 	resp, err := http.Get(ts.URL + "/test")
 	require.NoError(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	require.NoError(t, err)
 	defer resp.Body.Close()
 
@@ -62,7 +62,7 @@ func TestRest_RenderJSONWithHTML(t *testing.T) {
 	resp, err := http.Get(ts.URL + "/test")
 	require.NoError(t, err)
 	assert.Equal(t, 200, resp.StatusCode)
-	body, err := ioutil.ReadAll(resp.Body)
+	body, err := io.ReadAll(resp.Body)
 	require.NoError(t, err)
 	defer resp.Body.Close()
 	j2 := JSON{}
diff --git a/rewrite_test.go b/rewrite_test.go
index c24bde3..7efb850 100644
--- a/rewrite_test.go
+++ b/rewrite_test.go
@@ -20,7 +20,7 @@ func TestRewrite(t *testing.T) {
 	})
 
 	handler := Rewrite("/api/v1/(.*)", "/xyzzz/$1?foo=bar")(testHandler)
-	req, err := http.NewRequest("GET", "/api/v1/params", nil)
+	req, err := http.NewRequest("GET", "/api/v1/params", http.NoBody)
 	require.NoError(t, err)
 	handler.ServeHTTP(rr, req)
 }
@@ -36,7 +36,7 @@ func TestRewriteCleanup(t *testing.T) {
 	})
 
 	handler := Rewrite("/api/v1/(.*)", "/xyzzz/abc/../$1?foo=bar")(testHandler)
-	req, err := http.NewRequest("GET", "/api/v1/params", nil)
+	req, err := http.NewRequest("GET", "/api/v1/params", http.NoBody)
 	require.NoError(t, err)
 	handler.ServeHTTP(rr, req)
 }
@@ -52,7 +52,7 @@ func TestRewriteCleanupWithSlash(t *testing.T) {
 	})
 
 	handler := Rewrite("/api/v1/(.*)/", "/xyzzz/abc/../$1/")(testHandler)
-	req, err := http.NewRequest("GET", "/api/v1/params/", nil)
+	req, err := http.NewRequest("GET", "/api/v1/params/", http.NoBody)
 	require.NoError(t, err)
 	handler.ServeHTTP(rr, req)
 }
diff --git a/sizelimit.go b/sizelimit.go
index 6770e88..cfa0318 100644
--- a/sizelimit.go
+++ b/sizelimit.go
@@ -3,7 +3,6 @@ package rest
 import (
 	"bytes"
 	"io"
-	"io/ioutil"
 	"net/http"
 )
 
@@ -21,7 +20,7 @@ func SizeLimit(size int64) func(http.Handler) http.Handler {
 			}
 
 			// check size of the actual body
-			content, err := ioutil.ReadAll(io.LimitReader(r.Body, size+1))
+			content, err := io.ReadAll(io.LimitReader(r.Body, size+1))
 			if err != nil {
 				w.WriteHeader(http.StatusServiceUnavailable)
 				return
@@ -32,7 +31,7 @@ func SizeLimit(size int64) func(http.Handler) http.Handler {
 				w.WriteHeader(http.StatusRequestEntityTooLarge)
 				return
 			}
-			r.Body = ioutil.NopCloser(bytes.NewReader(content))
+			r.Body = io.NopCloser(bytes.NewReader(content))
 			h.ServeHTTP(w, r)
 		}
 
diff --git a/sizelimit_test.go b/sizelimit_test.go
index 2d19966..252e622 100644
--- a/sizelimit_test.go
+++ b/sizelimit_test.go
@@ -3,7 +3,6 @@ package rest
 import (
 	"fmt"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"net/http/httptest"
 	"net/http/httputil"
@@ -30,7 +29,7 @@ func TestSizeLimit(t *testing.T) {
 	}
 
 	handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		body, err := ioutil.ReadAll(r.Body)
+		body, err := io.ReadAll(r.Body)
 		require.NoError(t, err, "body read failed")
 		_, err = w.Write(body)
 		require.NoError(t, err, "body write failed")
@@ -50,7 +49,7 @@ func TestSizeLimit(t *testing.T) {
 				client := http.Client{Timeout: 1 * time.Second}
 				var reader io.Reader = strings.NewReader(tt.body)
 				if wrap {
-					reader = ioutil.NopCloser(reader) // to prevent ContentLength setting up
+					reader = io.NopCloser(reader) // to prevent ContentLength setting up
 				}
 				req, err := http.NewRequest(tt.method, fmt.Sprintf("%s/%d/%v", ts.URL, i, wrap), reader)
 				require.NoError(t, err)
@@ -59,7 +58,7 @@ func TestSizeLimit(t *testing.T) {
 				require.Equal(t, tt.code, resp.StatusCode)
 
 				if resp.StatusCode != http.StatusRequestEntityTooLarge {
-					body, err := ioutil.ReadAll(resp.Body)
+					body, err := io.ReadAll(resp.Body)
 					require.NoError(t, err)
 					defer resp.Body.Close()
 					assert.Equal(t, tt.body, string(body), "body match")
diff --git a/trace_test.go b/trace_test.go
index 7d15586..4ee1a80 100644
--- a/trace_test.go
+++ b/trace_test.go
@@ -1,7 +1,7 @@
 package rest
 
 import (
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"testing"
@@ -21,7 +21,7 @@ func TestTraceNoID(t *testing.T) {
 		defer func() { _ = res.Body.Close() }()
 	}
 
-	b, err := ioutil.ReadAll(res.Body)
+	b, err := io.ReadAll(res.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, 200, res.StatusCode)
 	assert.Equal(t, "blah", string(b))
@@ -46,7 +46,7 @@ func TestTraceWithID(t *testing.T) {
 	defer ts.Close()
 
 	client := http.Client{Timeout: 5 * time.Second}
-	req, err := http.NewRequest("GET", ts.URL+"/something", nil)
+	req, err := http.NewRequest("GET", ts.URL+"/something", http.NoBody)
 	assert.NoError(t, err)
 	req.Header.Add("X-Request-Id", "123456")
 	res, err := client.Do(req)
@@ -55,7 +55,7 @@ func TestTraceWithID(t *testing.T) {
 		defer func() { _ = res.Body.Close() }()
 	}
 
-	b, err := ioutil.ReadAll(res.Body)
+	b, err := io.ReadAll(res.Body)
 	assert.NoError(t, err)
 	assert.Equal(t, 200, res.StatusCode)
 	assert.Equal(t, "blah", string(b))