From e719c9d39bab0b70d2be1c772fd27a03b617aac7 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Fri, 28 Oct 2022 21:15:13 +0600 Subject: [PATCH] Get rid of io/ioutil usage --- etag/etag_test.go | 4 ++-- healthcheck.go | 4 ++-- imagedata/download.go | 4 ++-- imagemeta/heif.go | 3 +-- processing_handler_test.go | 8 ++++---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/etag/etag_test.go b/etag/etag_test.go index ab6ec769..c03c8c28 100644 --- a/etag/etag_test.go +++ b/etag/etag_test.go @@ -1,7 +1,7 @@ package etag import ( - "io/ioutil" + "io" "os" "strings" "testing" @@ -36,7 +36,7 @@ type EtagTestSuite struct { } func (s *EtagTestSuite) SetupSuite() { - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) } func (s *EtagTestSuite) TeardownSuite() { diff --git a/healthcheck.go b/healthcheck.go index 8396f376..df69fd4a 100644 --- a/healthcheck.go +++ b/healthcheck.go @@ -3,7 +3,7 @@ package main import ( "context" "fmt" - "io/ioutil" + "io" "net" "net/http" "os" @@ -36,7 +36,7 @@ func healthcheck() int { } defer res.Body.Close() - msg, _ := ioutil.ReadAll(res.Body) + msg, _ := io.ReadAll(res.Body) fmt.Fprintln(os.Stderr, string(msg)) if res.StatusCode != 200 { diff --git a/imagedata/download.go b/imagedata/download.go index 5f6c62b3..53768f91 100644 --- a/imagedata/download.go +++ b/imagedata/download.go @@ -4,7 +4,7 @@ import ( "compress/gzip" "crypto/tls" "fmt" - "io/ioutil" + "io" "net/http" "net/http/cookiejar" "time" @@ -190,7 +190,7 @@ func requestImage(imageURL string, header http.Header, jar *cookiejar.Jar) (*htt } if res.StatusCode != 200 { - body, _ := ioutil.ReadAll(res.Body) + body, _ := io.ReadAll(res.Body) res.Body.Close() status := 404 diff --git a/imagemeta/heif.go b/imagemeta/heif.go index 49b910dd..049b68d3 100644 --- a/imagemeta/heif.go +++ b/imagemeta/heif.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "github.com/imgproxy/imgproxy/v3/imagetype" ) @@ -55,7 +54,7 @@ func heifDiscardN(r io.Reader, n int64) error { return err } - _, err := io.CopyN(ioutil.Discard, r, n) + _, err := io.CopyN(io.Discard, r, n) return err } diff --git a/processing_handler_test.go b/processing_handler_test.go index 68e827d0..c5cbe740 100644 --- a/processing_handler_test.go +++ b/processing_handler_test.go @@ -3,7 +3,7 @@ package main import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -44,7 +44,7 @@ func (s *ProcessingHandlerTestSuite) SetupSuite() { err = initialize() require.Nil(s.T(), err) - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) s.router = buildRouter() } @@ -77,14 +77,14 @@ func (s *ProcessingHandlerTestSuite) readTestFile(name string) []byte { wd, err := os.Getwd() require.Nil(s.T(), err) - data, err := ioutil.ReadFile(filepath.Join(wd, "testdata", name)) + data, err := os.ReadFile(filepath.Join(wd, "testdata", name)) require.Nil(s.T(), err) return data } func (s *ProcessingHandlerTestSuite) readBody(res *http.Response) []byte { - data, err := ioutil.ReadAll(res.Body) + data, err := io.ReadAll(res.Body) require.Nil(s.T(), err) return data }