Skip to content

Commit 1aae5b2

Browse files
chore: delint ioutil usage (#962)
This also bumps the minimum supported version of Go to 1.16 (which itself has beel EOL for almost 3 years now) Co-authored-by: Vojtech Vitek (golang.cz) <[email protected]>
1 parent c6225e3 commit 1aae5b2

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

middleware/compress.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net"
1211
"net/http"
1312
"strings"
@@ -160,16 +159,14 @@ func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) {
160159
delete(c.encoders, encoding)
161160

162161
// If the encoder supports Resetting (IoReseterWriter), then it can be pooled.
163-
encoder := fn(ioutil.Discard, c.level)
164-
if encoder != nil {
165-
if _, ok := encoder.(ioResetterWriter); ok {
166-
pool := &sync.Pool{
167-
New: func() interface{} {
168-
return fn(ioutil.Discard, c.level)
169-
},
170-
}
171-
c.pooledEncoders[encoding] = pool
162+
encoder := fn(io.Discard, c.level)
163+
if _, ok := encoder.(ioResetterWriter); ok {
164+
pool := &sync.Pool{
165+
New: func() interface{} {
166+
return fn(io.Discard, c.level)
167+
},
172168
}
169+
c.pooledEncoders[encoding] = pool
173170
}
174171
// If the encoder is not in the pooledEncoders, add it to the normal encoders.
175172
if _, ok := c.pooledEncoders[encoding]; !ok {

middleware/middleware_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package middleware
33
import (
44
"crypto/tls"
55
"io"
6-
"io/ioutil"
76
"net/http"
87
"net/http/httptest"
98
"path"
@@ -93,7 +92,7 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io
9392
return nil, ""
9493
}
9594

96-
respBody, err := ioutil.ReadAll(resp.Body)
95+
respBody, err := io.ReadAll(resp.Body)
9796
if err != nil {
9897
t.Fatal(err)
9998
return nil, ""
@@ -123,7 +122,7 @@ func testRequestNoRedirect(t *testing.T, ts *httptest.Server, method, path strin
123122
return nil, ""
124123
}
125124

126-
respBody, err := ioutil.ReadAll(resp.Body)
125+
respBody, err := io.ReadAll(resp.Body)
127126
if err != nil {
128127
t.Fatal(err)
129128
return nil, ""

middleware/wrap_writer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package middleware
66
import (
77
"bufio"
88
"io"
9-
"io/ioutil"
109
"net"
1110
"net/http"
1211
)
@@ -108,7 +107,7 @@ func (b *basicWriter) Write(buf []byte) (n int, err error) {
108107
} else if b.tee != nil {
109108
n, err = b.tee.Write(buf)
110109
} else {
111-
n, err = ioutil.Discard.Write(buf)
110+
n, err = io.Discard.Write(buf)
112111
}
113112
b.bytes += n
114113
return n, err

mux_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"net"
109
"net/http"
1110
"net/http/httptest"
@@ -186,7 +185,7 @@ func TestMuxBasic(t *testing.T) {
186185
t.Fatal(err)
187186
}
188187

189-
body, err := ioutil.ReadAll(resp.Body)
188+
body, err := io.ReadAll(resp.Body)
190189
if err != nil {
191190
t.Fatal(err)
192191
}
@@ -1368,7 +1367,7 @@ func TestServeHTTPExistingContext(t *testing.T) {
13681367
}
13691368
req = req.WithContext(tc.Ctx)
13701369
r.ServeHTTP(resp, req)
1371-
b, err := ioutil.ReadAll(resp.Body)
1370+
b, err := io.ReadAll(resp.Body)
13721371
if err != nil {
13731372
t.Fatalf("%v", err)
13741373
}
@@ -1965,7 +1964,7 @@ func testRequest(t *testing.T, ts *httptest.Server, method, path string, body io
19651964
return nil, ""
19661965
}
19671966

1968-
respBody, err := ioutil.ReadAll(resp.Body)
1967+
respBody, err := io.ReadAll(resp.Body)
19691968
if err != nil {
19701969
t.Fatal(err)
19711970
return nil, ""

0 commit comments

Comments
 (0)