From 0cb62a41ee3a1cfefae9f64825cac0aa84ad80ef Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Sun, 18 Jun 2023 20:17:59 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil --- http_prettifier.go | 6 +++--- input_file_test.go | 3 +-- input_raw_test.go | 9 +++++---- input_tcp_test.go | 5 ++--- kafka.go | 4 ++-- output_http_test.go | 4 ++-- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/http_prettifier.go b/http_prettifier.go index 596c6b24..592799c7 100644 --- a/http_prettifier.go +++ b/http_prettifier.go @@ -5,7 +5,7 @@ import ( "compress/gzip" "fmt" "github.com/buger/goreplay/proto" - "io/ioutil" + "io" "net/http/httputil" "strconv" ) @@ -31,7 +31,7 @@ func prettifyHTTP(p []byte) []byte { if tEnc { buf := bytes.NewReader(content) r := httputil.NewChunkedReader(buf) - content, _ = ioutil.ReadAll(r) + content, _ = io.ReadAll(r) headers = proto.DeleteHeader(headers, []byte("Transfer-Encoding")) @@ -48,7 +48,7 @@ func prettifyHTTP(p []byte) []byte { return []byte{} } - content, err = ioutil.ReadAll(g) + content, err = io.ReadAll(g) if err != nil { Debug(1, fmt.Sprintf("[HTTP-PRETTIFIER] %q", err)) return p diff --git a/input_file_test.go b/input_file_test.go index 59d057e1..357a481f 100644 --- a/input_file_test.go +++ b/input_file_test.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "math/rand" "os" "sync" @@ -288,7 +287,7 @@ func (expectedCaptureFile *CaptureFile) PayloadsEqual(other []*Message) bool { } func CreateCaptureFile(requestGenerator *RequestGenerator) *CaptureFile { - f, err := ioutil.TempFile("", "testmainconf") + f, err := os.CreateTemp("", "testmainconf") if err != nil { panic(err) } diff --git a/input_raw_test.go b/input_raw_test.go index cf5e6673..2eb8c599 100644 --- a/input_raw_test.go +++ b/input_raw_test.go @@ -5,7 +5,8 @@ import ( "github.com/buger/goreplay/internal/capture" "github.com/buger/goreplay/internal/tcp" "github.com/buger/goreplay/proto" - "io/ioutil" + "io" + "os" "net" "net/http" "net/http/httptest" @@ -222,12 +223,12 @@ func TestRAWInputIPv6(t *testing.T) { func TestInputRAWChunkedEncoding(t *testing.T) { wg := new(sync.WaitGroup) - fileContent, _ := ioutil.ReadFile("README.md") + fileContent, _ := os.ReadFile("README.md") // Origing and Replay server initialization origin := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - ioutil.ReadAll(r.Body) + io.ReadAll(r.Body) wg.Done() })) @@ -244,7 +245,7 @@ func TestInputRAWChunkedEncoding(t *testing.T) { replay := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - body, _ := ioutil.ReadAll(r.Body) + body, _ := io.ReadAll(r.Body) if !bytes.Equal(body, fileContent) { buf, _ := httputil.DumpRequest(r, true) diff --git a/input_tcp_test.go b/input_tcp_test.go index 543b0d08..e152572e 100644 --- a/input_tcp_test.go +++ b/input_tcp_test.go @@ -7,7 +7,6 @@ import ( "crypto/tls" "crypto/x509" "encoding/pem" - "io/ioutil" "log" "math/big" "net" @@ -86,11 +85,11 @@ func TestTCPInputSecure(t *testing.T) { IPAddresses: []net.IP{net.ParseIP("127.0.0.1"), net.ParseIP("::")}, }) - serverCertPemFile, _ := ioutil.TempFile("", "server.crt") + serverCertPemFile, _ := os.CreateTemp("", "server.crt") serverCertPemFile.Write(serverCertPem) serverCertPemFile.Close() - serverPrivPemFile, _ := ioutil.TempFile("", "server.key") + serverPrivPemFile, _ := os.CreateTemp("", "server.key") serverPrivPemFile.Write(serverPrivPem) serverPrivPemFile.Close() diff --git a/kafka.go b/kafka.go index f1497701..87a09f13 100644 --- a/kafka.go +++ b/kafka.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" "github.com/buger/goreplay/proto" - "io/ioutil" + "os" "log" "github.com/Shopify/sarama" @@ -82,7 +82,7 @@ func NewTLSConfig(clientCertFile, clientKeyFile, caCertFile string) (*tls.Config } // Load CA cert if caCertFile != "" { - caCert, err := ioutil.ReadFile(caCertFile) + caCert, err := os.ReadFile(caCertFile) if err != nil { return &tlsConfig, err } diff --git a/output_http_test.go b/output_http_test.go index d884609b..4371202c 100644 --- a/output_http_test.go +++ b/output_http_test.go @@ -1,7 +1,7 @@ package goreplay import ( - "io/ioutil" + "io" "net/http" "net/http/httptest" _ "net/http/httputil" @@ -25,7 +25,7 @@ func TestHTTPOutput(t *testing.T) { if req.Method == "POST" { defer req.Body.Close() - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) if string(body) != "a=1&b=2" { t.Error("Wrong POST body:", string(body))