Skip to content

Commit

Permalink
chore: delint ioutil usage (#962)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
costela and VojtechVitek authored Feb 12, 2025
1 parent c6225e3 commit 1aae5b2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
17 changes: 7 additions & 10 deletions middleware/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -160,16 +159,14 @@ 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)
if encoder != nil {
if _, ok := encoder.(ioResetterWriter); ok {
pool := &sync.Pool{
New: func() interface{} {
return fn(ioutil.Discard, c.level)
},
}
c.pooledEncoders[encoding] = pool
encoder := fn(io.Discard, c.level)
if _, ok := encoder.(ioResetterWriter); ok {
pool := &sync.Pool{
New: func() interface{} {
return fn(io.Discard, c.level)
},
}
c.pooledEncoders[encoding] = pool
}
// If the encoder is not in the pooledEncoders, add it to the normal encoders.
if _, ok := c.pooledEncoders[encoding]; !ok {
Expand Down
5 changes: 2 additions & 3 deletions middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package middleware
import (
"crypto/tls"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"path"
Expand Down Expand Up @@ -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, ""
Expand Down Expand Up @@ -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, ""
Expand Down
3 changes: 1 addition & 2 deletions middleware/wrap_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package middleware
import (
"bufio"
"io"
"io/ioutil"
"net"
"net/http"
)
Expand Down Expand Up @@ -108,7 +107,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
Expand Down
7 changes: 3 additions & 4 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -1965,7 +1964,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, ""
Expand Down

0 comments on commit 1aae5b2

Please sign in to comment.