diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c4b58852203..570dd71a137 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,7 +25,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "1.19.x" - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: - version: v1.45.2 + version: v1.48.0 diff --git a/example/main.go b/example/main.go index e45245b5d03..9d7a7d8edb7 100644 --- a/example/main.go +++ b/example/main.go @@ -7,7 +7,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "mime/multipart" "net/http" @@ -93,7 +92,7 @@ func setupHandler(www string) http.Handler { }) mux.HandleFunc("/demo/echo", func(w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { fmt.Printf("error reading body while handling /echo: %s\n", err.Error()) } diff --git a/fuzzing/frames/fuzz.go b/fuzzing/frames/fuzz.go index cd0409bc894..cf1f0e530dc 100644 --- a/fuzzing/frames/fuzz.go +++ b/fuzzing/frames/fuzz.go @@ -25,6 +25,7 @@ func toEncLevel(v uint8) protocol.EncryptionLevel { } // Fuzz fuzzes the QUIC frames. +// //go:generate go run ./cmd/corpus.go func Fuzz(data []byte) int { if len(data) < PrefixLen { diff --git a/fuzzing/handshake/fuzz.go b/fuzzing/handshake/fuzz.go index c761ad0ca41..5faf478a857 100644 --- a/fuzzing/handshake/fuzz.go +++ b/fuzzing/handshake/fuzz.go @@ -7,7 +7,7 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" + "io" "log" "math" mrand "math/rand" @@ -249,6 +249,7 @@ const ( ) // Fuzz fuzzes the TLS 1.3 handshake used by QUIC. +// //go:generate go run ./cmd/corpus.go func Fuzz(data []byte) int { if len(data) < PrefixLen { @@ -353,10 +354,10 @@ func runHandshake(runConfig [confLen]byte, messageConfig uint8, clientConf *tls. serverConf.NextProtos = []string{alpnWrong, alpn} } if helper.NthBit(runConfig[3], 6) { - serverConf.KeyLogWriter = ioutil.Discard + serverConf.KeyLogWriter = io.Discard } if helper.NthBit(runConfig[3], 7) { - clientConf.KeyLogWriter = ioutil.Discard + clientConf.KeyLogWriter = io.Discard } clientTP := getTransportParameters(runConfig[4] & 0x3) if helper.NthBit(runConfig[4], 3) { diff --git a/fuzzing/header/fuzz.go b/fuzzing/header/fuzz.go index be7564b9e48..ba37172e209 100644 --- a/fuzzing/header/fuzz.go +++ b/fuzzing/header/fuzz.go @@ -14,6 +14,7 @@ const version = protocol.VersionTLS const PrefixLen = 1 // Fuzz fuzzes the QUIC header. +// //go:generate go run ./cmd/corpus.go func Fuzz(data []byte) int { if len(data) < PrefixLen { diff --git a/fuzzing/internal/helper/helper.go b/fuzzing/internal/helper/helper.go index c621182036c..52e47f21f9f 100644 --- a/fuzzing/internal/helper/helper.go +++ b/fuzzing/internal/helper/helper.go @@ -8,7 +8,6 @@ import ( "crypto/x509" "crypto/x509/pkix" "encoding/hex" - "io/ioutil" "math/big" "os" "path/filepath" @@ -33,7 +32,7 @@ func WriteCorpusFile(path string, data []byte) error { } } hash := sha1.Sum(data) - return ioutil.WriteFile(filepath.Join(path, hex.EncodeToString(hash[:])), data, 0o644) + return os.WriteFile(filepath.Join(path, hex.EncodeToString(hash[:])), data, 0o644) } // WriteCorpusFileWithPrefix writes data to a corpus file in directory path. diff --git a/fuzzing/internal/helper/helper_test.go b/fuzzing/internal/helper/helper_test.go index 6bee7d9196f..2d4045668c4 100644 --- a/fuzzing/internal/helper/helper_test.go +++ b/fuzzing/internal/helper/helper_test.go @@ -2,7 +2,6 @@ package helper import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -15,7 +14,7 @@ var _ = Describe("exporting", func() { BeforeEach(func() { var err error - dir, err = ioutil.TempDir("", "fuzzing-helper") + dir, err = os.MkdirTemp("", "fuzzing-helper") Expect(err).ToNot(HaveOccurred()) fmt.Fprintf(GinkgoWriter, "Created temporary directory %s", dir) }) @@ -32,7 +31,7 @@ var _ = Describe("exporting", func() { Expect(WriteCorpusFile(dir, []byte("lorem ipsum"))).To(Succeed()) path := filepath.Join(dir, expectedShaSum) Expect(path).To(BeARegularFile()) - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) Expect(err).ToNot(HaveOccurred()) Expect(string(b)).To(Equal(data)) }) @@ -45,7 +44,7 @@ var _ = Describe("exporting", func() { Expect(WriteCorpusFileWithPrefix(dir, []byte("lorem ipsum"), prefixLen)).To(Succeed()) path := filepath.Join(dir, expectedShaSum) Expect(path).To(BeARegularFile()) - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) Expect(err).ToNot(HaveOccurred()) Expect(b[:prefixLen]).To(Equal(make([]byte, prefixLen))) Expect(string(b[prefixLen:])).To(Equal(data)) diff --git a/fuzzing/transportparameters/fuzz.go b/fuzzing/transportparameters/fuzz.go index 0b3529539e0..a11fc5a1379 100644 --- a/fuzzing/transportparameters/fuzz.go +++ b/fuzzing/transportparameters/fuzz.go @@ -13,6 +13,7 @@ import ( const PrefixLen = 1 // Fuzz fuzzes the QUIC transport parameters. +// //go:generate go run ./cmd/corpus.go func Fuzz(data []byte) int { if len(data) <= PrefixLen { diff --git a/http3/client_test.go b/http3/client_test.go index c7075ef1847..beaf29f8345 100644 --- a/http3/client_test.go +++ b/http3/client_test.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "time" @@ -990,7 +989,7 @@ var _ = Describe("Client", func() { rsp, err := client.RoundTripOpt(req, RoundTripOpt{}) Expect(err).ToNot(HaveOccurred()) - data, err := ioutil.ReadAll(rsp.Body) + data, err := io.ReadAll(rsp.Body) Expect(err).ToNot(HaveOccurred()) Expect(rsp.ContentLength).To(BeEquivalentTo(-1)) Expect(string(data)).To(Equal("gzipped response")) @@ -1013,7 +1012,7 @@ var _ = Describe("Client", func() { rsp, err := client.RoundTripOpt(req, RoundTripOpt{}) Expect(err).ToNot(HaveOccurred()) - data, err := ioutil.ReadAll(rsp.Body) + data, err := io.ReadAll(rsp.Body) Expect(err).ToNot(HaveOccurred()) Expect(string(data)).To(Equal("not gzipped")) Expect(rsp.Header.Get("Content-Encoding")).To(BeEmpty()) diff --git a/http3/frames.go b/http3/frames.go index 474aab48e5f..af9f28eb9f5 100644 --- a/http3/frames.go +++ b/http3/frames.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/quicvarint" @@ -65,7 +64,7 @@ func parseNextFrame(r io.Reader, unknownFrameHandler unknownFrameHandlerFunc) (f case 0xd: // MAX_PUSH_ID } // skip over unknown frames - if _, err := io.CopyN(ioutil.Discard, qr, int64(l)); err != nil { + if _, err := io.CopyN(io.Discard, qr, int64(l)); err != nil { return nil, err } } diff --git a/http3/request_writer.go b/http3/request_writer.go index 0a9c67ac5d7..3dd1cbaef34 100644 --- a/http3/request_writer.go +++ b/http3/request_writer.go @@ -233,8 +233,8 @@ func authorityAddr(scheme string, authority string) (addr string) { // validPseudoPath reports whether v is a valid :path pseudo-header // value. It must be either: // -// *) a non-empty string starting with '/' -// *) the string '*', for OPTIONS requests. +// *) a non-empty string starting with '/' +// *) the string '*', for OPTIONS requests. // // For now this is only used a quick check for deciding when to clean // up Opaque URLs before sending requests from the Transport. diff --git a/http3/server.go b/http3/server.go index 0432a615653..499bdc7658f 100644 --- a/http3/server.go +++ b/http3/server.go @@ -637,7 +637,8 @@ var ErrNoAltSvcPort = errors.New("no port can be announced, specify it explicitl // If no listener's Addr().String() returns an address with a valid port, Server.Addr will be used // to extract the port, if specified. // For example, a server launched using ListenAndServe on an address with port 443 would set: -// Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 +// +// Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000 func (s *Server) SetQuicHeaders(hdr http.Header) error { s.mutex.RLock() defer s.mutex.RUnlock() diff --git a/integrationtests/self/tracer_test.go b/integrationtests/self/tracer_test.go index f244381c8aa..f0f7680bd91 100644 --- a/integrationtests/self/tracer_test.go +++ b/integrationtests/self/tracer_test.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "io" - "io/ioutil" mrand "math/rand" "net" "time" @@ -90,7 +89,7 @@ var _ = Describe("Handshake tests", func() { return nil } fmt.Fprintf(GinkgoWriter, "%s qlog tracing connection %x\n", p, connectionID) - return utils.NewBufferedWriteCloser(bufio.NewWriter(&bytes.Buffer{}), ioutil.NopCloser(nil)) + return utils.NewBufferedWriteCloser(bufio.NewWriter(&bytes.Buffer{}), io.NopCloser(nil)) })) } if enableCustomTracer { diff --git a/internal/flowcontrol/base_flow_controller_test.go b/internal/flowcontrol/base_flow_controller_test.go index aa68fe54d9d..01fa97f0773 100644 --- a/internal/flowcontrol/base_flow_controller_test.go +++ b/internal/flowcontrol/base_flow_controller_test.go @@ -13,6 +13,7 @@ import ( ) // on the CIs, the timing is a lot less precise, so scale every duration by this factor +// //nolint:unparam func scaleDuration(t time.Duration) time.Duration { scaleFactor := 1 diff --git a/internal/testdata/cert.go b/internal/testdata/cert.go index f862b0cbcab..6cc7a091e51 100644 --- a/internal/testdata/cert.go +++ b/internal/testdata/cert.go @@ -3,7 +3,7 @@ package testdata import ( "crypto/tls" "crypto/x509" - "io/ioutil" + "os" "path" "runtime" ) @@ -38,7 +38,7 @@ func GetTLSConfig() *tls.Config { // AddRootCA adds the root CA certificate to a cert pool func AddRootCA(certPool *x509.CertPool) { caCertPath := path.Join(certPath, "ca.pem") - caCertRaw, err := ioutil.ReadFile(caCertPath) + caCertRaw, err := os.ReadFile(caCertPath) if err != nil { panic(err) } diff --git a/internal/testdata/cert_test.go b/internal/testdata/cert_test.go index 0de1bd7bbcf..1d446f4caa4 100644 --- a/internal/testdata/cert_test.go +++ b/internal/testdata/cert_test.go @@ -2,7 +2,7 @@ package testdata import ( "crypto/tls" - "io/ioutil" + "io" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -24,7 +24,7 @@ var _ = Describe("certificates", func() { conn, err := tls.Dial("tcp", "localhost:4433", &tls.Config{RootCAs: GetRootCA()}) Expect(err).ToNot(HaveOccurred()) - data, err := ioutil.ReadAll(conn) + data, err := io.ReadAll(conn) Expect(err).ToNot(HaveOccurred()) Expect(string(data)).To(Equal("foobar")) }) diff --git a/interop/http09/client.go b/interop/http09/client.go index cf2a03276bf..4529f22735f 100644 --- a/interop/http09/client.go +++ b/interop/http09/client.go @@ -4,7 +4,7 @@ import ( "context" "crypto/tls" "errors" - "io/ioutil" + "io" "log" "net" "net/http" @@ -118,7 +118,7 @@ func (c *client) doRequest(req *http.Request) (*http.Response, error) { ProtoMajor: 0, ProtoMinor: 9, Request: req, - Body: ioutil.NopCloser(str), + Body: io.NopCloser(str), } return rsp, nil } diff --git a/interop/http09/http_test.go b/interop/http09/http_test.go index 4942135c625..2c158e012b1 100644 --- a/interop/http09/http_test.go +++ b/interop/http09/http_test.go @@ -3,7 +3,7 @@ package http09 import ( "crypto/tls" "fmt" - "io/ioutil" + "io" "net" "net/http" "net/http/httptest" @@ -62,7 +62,7 @@ var _ = Describe("HTTP 0.9 integration tests", func() { ) rsp, err := rt.RoundTrip(req) Expect(err).ToNot(HaveOccurred()) - data, err := ioutil.ReadAll(rsp.Body) + data, err := io.ReadAll(rsp.Body) Expect(err).ToNot(HaveOccurred()) Expect(data).To(Equal([]byte("Hello World!"))) }) @@ -83,7 +83,7 @@ var _ = Describe("HTTP 0.9 integration tests", func() { ) rsp, err := rt.RoundTrip(req) Expect(err).ToNot(HaveOccurred()) - data, err := ioutil.ReadAll(rsp.Body) + data, err := io.ReadAll(rsp.Body) Expect(err).ToNot(HaveOccurred()) Expect(data).To(Equal([]byte("done"))) }) diff --git a/interop/http09/server.go b/interop/http09/server.go index 59665bd64ca..864901a636e 100644 --- a/interop/http09/server.go +++ b/interop/http09/server.go @@ -4,7 +4,6 @@ import ( "context" "errors" "io" - "io/ioutil" "log" "net" "net/http" @@ -102,7 +101,7 @@ func (s *Server) handleConn(conn quic.Connection) { } func (s *Server) handleStream(str quic.Stream) error { - reqBytes, err := ioutil.ReadAll(str) + reqBytes, err := io.ReadAll(str) if err != nil { return err } diff --git a/quic_suite_test.go b/quic_suite_test.go index d8a0a2e0cbd..6d9a37419b5 100644 --- a/quic_suite_test.go +++ b/quic_suite_test.go @@ -1,7 +1,7 @@ package quic import ( - "io/ioutil" + "io" "log" "sync" "testing" @@ -26,7 +26,7 @@ var _ = BeforeEach(func() { }) var _ = BeforeSuite(func() { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) }) var _ = AfterEach(func() {