Skip to content

Commit a696949

Browse files
authored
Deprecate Go 1.15 (valyala#1379)
* Dropping support for 1.15. * Replaces Go 1.16 Deprecated functions * Update test build flag * Fix import sort and comment * Update github.com/klauspost/compress to v1.15.9 https://github.com/klauspost/compress improved performance and changed Minimum version is 1.16, this should be the final supported release for Go 1.16 (klauspost/compress@6d0019a) .
1 parent 2f1e949 commit a696949

24 files changed

+73
-94
lines changed

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
test:
99
strategy:
1010
matrix:
11-
go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x]
11+
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x]
1212
os: [ubuntu-latest, macos-latest, windows-latest]
1313
runs-on: ${{ matrix.os }}
1414
steps:

Diff for: allocation_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package fasthttp
55

66
import (
77
"net"
8-
98
"testing"
109
)
1110

Diff for: brotli_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bufio"
55
"bytes"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"testing"
99
)
1010

@@ -91,7 +91,7 @@ func testBrotliCompressSingleCase(s string) error {
9191
if err != nil {
9292
return fmt.Errorf("unexpected error: %w. s=%q", err, s)
9393
}
94-
body, err := ioutil.ReadAll(zr)
94+
body, err := io.ReadAll(zr)
9595
if err != nil {
9696
return fmt.Errorf("unexpected error: %w. s=%q", err, s)
9797
}

Diff for: bytesconv_table_gen.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package main
66
import (
77
"bytes"
88
"fmt"
9-
"io/ioutil"
109
"log"
1110
)
1211

@@ -107,7 +106,7 @@ func main() {
107106
fmt.Fprintf(w, "const quotedArgShouldEscapeTable = %q\n", quotedArgShouldEscapeTable)
108107
fmt.Fprintf(w, "const quotedPathShouldEscapeTable = %q\n", quotedPathShouldEscapeTable)
109108

110-
if err := ioutil.WriteFile("bytesconv_table.go", w.Bytes(), 0660); err != nil {
109+
if err := os.WriteFile("bytesconv_table.go", w.Bytes(), 0660); err != nil {
111110
log.Fatal(err)
112111
}
113112
}

Diff for: client_timing_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package fasthttp
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net"
88
"net/http"
99
"runtime"
@@ -169,7 +169,7 @@ func BenchmarkNetHTTPClientDoFastServer(b *testing.B) {
169169
if resp.StatusCode != http.StatusOK {
170170
b.Fatalf("unexpected status code: %d", resp.StatusCode)
171171
}
172-
respBody, err := ioutil.ReadAll(resp.Body)
172+
respBody, err := io.ReadAll(resp.Body)
173173
resp.Body.Close()
174174
if err != nil {
175175
b.Fatalf("unexpected error when reading response body: %v", err)
@@ -297,7 +297,7 @@ func benchmarkNetHTTPClientGetEndToEndTCP(b *testing.B, parallelism int) {
297297
if resp.StatusCode != http.StatusOK {
298298
b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK)
299299
}
300-
body, err := ioutil.ReadAll(resp.Body)
300+
body, err := io.ReadAll(resp.Body)
301301
resp.Body.Close()
302302
if err != nil {
303303
b.Fatalf("unexpected error when reading response body: %v", err)
@@ -427,7 +427,7 @@ func benchmarkNetHTTPClientGetEndToEndInmemory(b *testing.B, parallelism int) {
427427
if resp.StatusCode != http.StatusOK {
428428
b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK)
429429
}
430-
body, err := ioutil.ReadAll(resp.Body)
430+
body, err := io.ReadAll(resp.Body)
431431
resp.Body.Close()
432432
if err != nil {
433433
b.Fatalf("unexpected error when reading response body: %v", err)
@@ -554,7 +554,7 @@ func benchmarkNetHTTPClientEndToEndBigResponseInmemory(b *testing.B, parallelism
554554
if resp.StatusCode != http.StatusOK {
555555
b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK)
556556
}
557-
body, err := ioutil.ReadAll(resp.Body)
557+
body, err := io.ReadAll(resp.Body)
558558
resp.Body.Close()
559559
if err != nil {
560560
b.Fatalf("unexpected error when reading response body: %v", err)

Diff for: client_timing_wait_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
//go:build go1.11
2-
// +build go1.11
3-
41
package fasthttp
52

63
import (
7-
"io/ioutil"
4+
"io"
85
"net"
96
"net/http"
107
"strings"
@@ -146,7 +143,7 @@ func benchmarkNetHTTPClientGetEndToEndWaitConnInmemory(b *testing.B, parallelism
146143
if resp.StatusCode != http.StatusOK {
147144
b.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode, http.StatusOK)
148145
}
149-
body, err := ioutil.ReadAll(resp.Body)
146+
body, err := io.ReadAll(resp.Body)
150147
resp.Body.Close()
151148
if err != nil {
152149
b.Fatalf("unexpected error when reading response body: %v", err)

Diff for: client_unix_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package fasthttp
55

66
import (
77
"io"
8-
"io/ioutil"
98
"net"
109
"net/http"
1110
"strings"
@@ -32,7 +31,7 @@ func TestRstConnResponseWhileSending(t *testing.T) {
3231

3332
// Read at least one byte of the header
3433
// Otherwise we would have an unsolicited response
35-
_, err = ioutil.ReadAll(io.LimitReader(conn, 1))
34+
_, err = io.ReadAll(io.LimitReader(conn, 1))
3635
if err != nil {
3736
t.Error(err)
3837
}
@@ -94,7 +93,7 @@ func TestRstConnClosedWithoutResponse(t *testing.T) {
9493

9594
// Read at least one byte of the header
9695
// Otherwise we would have an unsolicited response
97-
_, err = ioutil.ReadAll(io.LimitReader(conn, 1))
96+
_, err = io.ReadAll(io.LimitReader(conn, 1))
9897
if err != nil {
9998
t.Error(err)
10099
}

Diff for: compress_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package fasthttp
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"testing"
88
"time"
99
)
@@ -173,7 +173,7 @@ func testGzipCompressSingleCase(s string) error {
173173
if err != nil {
174174
return fmt.Errorf("unexpected error: %w. s=%q", err, s)
175175
}
176-
body, err := ioutil.ReadAll(zr)
176+
body, err := io.ReadAll(zr)
177177
if err != nil {
178178
return fmt.Errorf("unexpected error: %w. s=%q", err, s)
179179
}
@@ -196,7 +196,7 @@ func testFlateCompressSingleCase(s string) error {
196196
if err != nil {
197197
return fmt.Errorf("unexpected error: %w. s=%q", err, s)
198198
}
199-
body, err := ioutil.ReadAll(zr)
199+
body, err := io.ReadAll(zr)
200200
if err != nil {
201201
return fmt.Errorf("unexpected error: %w. s=%q", err, s)
202202
}

Diff for: fasthttpadaptor/adaptor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package fasthttpadaptor
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net"
77
"net/http"
88
"net/url"
@@ -66,7 +66,7 @@ func TestNewFastHTTPHandler(t *testing.T) {
6666
if r.RemoteAddr != expectedRemoteAddr {
6767
t.Fatalf("unexpected remoteAddr %q. Expecting %q", r.RemoteAddr, expectedRemoteAddr)
6868
}
69-
body, err := ioutil.ReadAll(r.Body)
69+
body, err := io.ReadAll(r.Body)
7070
r.Body.Close()
7171
if err != nil {
7272
t.Fatalf("unexpected error when reading request body: %v", err)

Diff for: fasthttpadaptor/request.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package fasthttpadaptor
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/url"
88

@@ -28,7 +28,7 @@ func ConvertRequest(ctx *fasthttp.RequestCtx, r *http.Request, forServer bool) e
2828
r.RemoteAddr = ctx.RemoteAddr().String()
2929
r.Host = string(ctx.Host())
3030
r.TLS = ctx.TLSConnectionState()
31-
r.Body = ioutil.NopCloser(bytes.NewReader(body))
31+
r.Body = io.NopCloser(bytes.NewReader(body))
3232
r.URL = rURL
3333

3434
if forServer {

Diff for: fasthttpproxy/proxy_env.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import (
99
"sync/atomic"
1010
"time"
1111

12-
"golang.org/x/net/http/httpproxy"
13-
1412
"github.com/valyala/fasthttp"
13+
"golang.org/x/net/http/httpproxy"
1514
)
1615

1716
const (
@@ -32,7 +31,7 @@ func FasthttpProxyHTTPDialer() fasthttp.DialFunc {
3231
return FasthttpProxyHTTPDialerTimeout(0)
3332
}
3433

35-
// FasthttpProxyHTTPDialer returns a fasthttp.DialFunc that dials using
34+
// FasthttpProxyHTTPDialerTimeout returns a fasthttp.DialFunc that dials using
3635
// the env(HTTP_PROXY, HTTPS_PROXY and NO_PROXY) configured HTTP proxy using the given timeout.
3736
//
3837
// Example usage:

Diff for: fasthttputil/inmemory_listener_test.go

+1-2
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
"sync"
@@ -147,7 +146,7 @@ func testInmemoryListenerHTTPSingle(t *testing.T, client *http.Client, content s
147146
if err != nil {
148147
t.Fatalf("unexpected error: %v", err)
149148
}
150-
b, err := ioutil.ReadAll(res.Body)
149+
b, err := io.ReadAll(res.Body)
151150
if err != nil {
152151
t.Fatalf("unexpected error: %v", err)
153152
}

Diff for: fasthttputil/pipeconns_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net"
98
"testing"
109
"time"
@@ -162,7 +161,7 @@ func testPipeConnsCloseWhileReadWrite(t *testing.T) {
162161
readCh := make(chan error)
163162
go func() {
164163
var err error
165-
if _, err = io.Copy(ioutil.Discard, c1); err != nil {
164+
if _, err = io.Copy(io.Discard, c1); err != nil {
166165
if err != errConnectionClosed {
167166
err = fmt.Errorf("unexpected error: %w", err)
168167
} else {

Diff for: fs.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"html"
88
"io"
9-
"io/ioutil"
109
"mime"
1110
"net/http"
1211
"os"
@@ -1377,7 +1376,7 @@ func readFileHeader(f *os.File, compressed bool, fileEncoding string) ([]byte, e
13771376
R: r,
13781377
N: 512,
13791378
}
1380-
data, err := ioutil.ReadAll(lr)
1379+
data, err := io.ReadAll(lr)
13811380
if _, err := f.Seek(0, 0); err != nil {
13821381
return nil, err
13831382
}

Diff for: fs_test.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
// go:build !windows
2-
// Don't run FS tests on windows as it isn't compatible for now.
3-
41
package fasthttp
52

63
import (
74
"bufio"
85
"bytes"
96
"fmt"
107
"io"
11-
"io/ioutil"
128
"math/rand"
139
"os"
1410
"path"
@@ -158,13 +154,13 @@ func TestServeFileSmallNoReadFrom(t *testing.T) {
158154

159155
teststr := "hello, world!"
160156

161-
tempdir, err := ioutil.TempDir("", "httpexpect")
157+
tempdir, err := os.MkdirTemp("", "httpexpect")
162158
if err != nil {
163159
t.Fatal(err)
164160
}
165161
defer os.RemoveAll(tempdir)
166162

167-
if err := ioutil.WriteFile(
163+
if err := os.WriteFile(
168164
path.Join(tempdir, "hello"), []byte(teststr), 0666); err != nil {
169165
t.Fatal(err)
170166
}
@@ -412,7 +408,7 @@ func getFileContents(path string) ([]byte, error) {
412408
return nil, err
413409
}
414410
defer f.Close()
415-
return ioutil.ReadAll(f)
411+
return io.ReadAll(f)
416412
}
417413

418414
func TestParseByteRangeSuccess(t *testing.T) {
@@ -703,7 +699,7 @@ func fsHandlerTest(t *testing.T, requestHandler RequestHandler, filenames []stri
703699
f.Close()
704700
continue
705701
}
706-
data, err := ioutil.ReadAll(f)
702+
data, err := io.ReadAll(f)
707703
f.Close()
708704
if err != nil {
709705
t.Fatalf("cannot read file contents %q: %v", name, err)
@@ -714,7 +710,7 @@ func fsHandlerTest(t *testing.T, requestHandler RequestHandler, filenames []stri
714710
if ctx.Response.bodyStream == nil {
715711
t.Fatalf("response body stream must be non-empty")
716712
}
717-
body, err := ioutil.ReadAll(ctx.Response.bodyStream)
713+
body, err := io.ReadAll(ctx.Response.bodyStream)
718714
if err != nil {
719715
t.Fatalf("error when reading response body stream: %v", err)
720716
}
@@ -733,7 +729,7 @@ func fsHandlerTest(t *testing.T, requestHandler RequestHandler, filenames []stri
733729
if ctx.Response.bodyStream == nil {
734730
t.Fatalf("response body stream must be non-empty")
735731
}
736-
body, err := ioutil.ReadAll(ctx.Response.bodyStream)
732+
body, err := io.ReadAll(ctx.Response.bodyStream)
737733
if err != nil {
738734
t.Fatalf("error when reading response body stream: %v", err)
739735
}

Diff for: go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/valyala/fasthttp
22

3-
go 1.15
3+
go 1.16
44

55
require (
66
github.com/andybalholm/brotli v1.0.4
7-
github.com/klauspost/compress v1.15.0
7+
github.com/klauspost/compress v1.15.9
88
github.com/valyala/bytebufferpool v1.0.0
99
github.com/valyala/tcplisten v1.0.0
1010
golang.org/x/crypto v0.0.0-20220214200702-86341886e292

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
22
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
3-
github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U=
4-
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
3+
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
4+
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
55
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
66
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
77
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=

0 commit comments

Comments
 (0)