From 16e3ce80006975ff2b81d286191400de1f5223bf Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 29 Aug 2024 07:25:55 +0100 Subject: [PATCH] Replace deprecated ioutil.ReadAll with io.ReadAll This bumps the minimum go version from go1.15 to go1.16 as io.ReadAll was only added in go1.16 --- go.mod | 2 +- slo.go | 4 ++-- swift.go | 3 +-- swift_test.go | 7 +++---- swifttest/server.go | 9 ++++----- timeout_reader_test.go | 5 ++--- watchdog_reader_test.go | 5 ++--- 7 files changed, 15 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 501c1ba01..c8b832234 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/ncw/swift/v2 -go 1.15 +go 1.16 diff --git a/slo.go b/slo.go index 45be15efe..00990d1bb 100644 --- a/slo.go +++ b/slo.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/url" "os" ) @@ -160,7 +160,7 @@ func (c *Connection) getAllSLOSegments(ctx context.Context, container, path stri return "", nil, err } - content, err := ioutil.ReadAll(file) + content, err := io.ReadAll(file) if err != nil { return "", nil, err } diff --git a/swift.go b/swift.go index 0a1813e6d..a11986eb3 100644 --- a/swift.go +++ b/swift.go @@ -12,7 +12,6 @@ import ( "fmt" "hash" "io" - "io/ioutil" "mime" "net/http" "net/url" @@ -364,7 +363,7 @@ func drainAndClose(rd io.ReadCloser, err *error) { return } - _, _ = io.Copy(ioutil.Discard, rd) + _, _ = io.Copy(io.Discard, rd) cerr := rd.Close() if err != nil && *err == nil { *err = cerr diff --git a/swift_test.go b/swift_test.go index cb39a4753..12f03dddb 100644 --- a/swift_test.go +++ b/swift_test.go @@ -23,7 +23,6 @@ import ( "encoding/xml" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -1457,7 +1456,7 @@ func TestObjectOpenSeekEnd(t *testing.T) { } // read file and check contents - buf, err = ioutil.ReadAll(file) + buf, err = io.ReadAll(file) if err != nil { t.Fatal(err) } @@ -2191,7 +2190,7 @@ func TestTempUrl(t *testing.T) { t.Fatal("HTTP Error retrieving file from temporary url", resp.StatusCode) } else { var content []byte - if content, err = ioutil.ReadAll(resp.Body); err != nil || string(content) != CONTENTS { + if content, err = io.ReadAll(resp.Body); err != nil || string(content) != CONTENTS { t.Error("Bad content", err) } @@ -2639,7 +2638,7 @@ func TestDLOConcurrentWrite(t *testing.T) { for j := 0; j < nChunks; j++ { var data []byte var n int - data, err = ioutil.ReadAll(io.LimitReader(rand.Reader, chunkSize)) + data, err = io.ReadAll(io.LimitReader(rand.Reader, chunkSize)) if err != nil { t.Fatal(err) } diff --git a/swifttest/server.go b/swifttest/server.go index 84040d14e..dc3f29e55 100644 --- a/swifttest/server.go +++ b/swifttest/server.go @@ -18,7 +18,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "mime" "net" @@ -373,7 +372,7 @@ func (r containerResource) put(a *action) interface{} { if format := a.req.URL.Query().Get("extract-archive"); format != "" { _, _, objectName, _ := a.srv.parseURL(a.req.URL) - data, err := ioutil.ReadAll(a.req.Body) + data, err := io.ReadAll(a.req.Body) if err != nil { fatalf(400, "TODO", "read error") } @@ -464,7 +463,7 @@ func (r containerResource) put(a *action) interface{} { } sum := md5.New() - objData, err := ioutil.ReadAll(io.TeeReader(reader, sum)) + objData, err := io.ReadAll(io.TeeReader(reader, sum)) if err != nil { errArr := []string{fullPath, fmt.Sprintf("read error: %v", err)} resp.Errors = append(resp.Errors, errArr) @@ -728,7 +727,7 @@ func (objr objectResource) put(a *action) interface{} { } sum := md5.New() // TODO avoid holding lock while reading data. - data, err := ioutil.ReadAll(io.TeeReader(a.req.Body, sum)) + data, err := io.ReadAll(io.TeeReader(a.req.Body, sum)) if err != nil { fatalf(400, "TODO", "read error") } @@ -1219,7 +1218,7 @@ func (r rootResource) post(a *action) interface{} { func (r rootResource) delete(a *action) interface{} { if a.req.URL.Query().Get("bulk-delete") == "1" { - data, err := ioutil.ReadAll(a.req.Body) + data, err := io.ReadAll(a.req.Body) if err != nil { fatalf(400, "Bad Request", "read error") } diff --git a/timeout_reader_test.go b/timeout_reader_test.go index 5eba09343..ef2686309 100644 --- a/timeout_reader_test.go +++ b/timeout_reader_test.go @@ -4,7 +4,6 @@ package swift import ( "io" - "io/ioutil" "sync" "testing" "time" @@ -54,7 +53,7 @@ func TestTimeoutReaderNoTimeout(t *testing.T) { cancelled = true } tr := newTimeoutReader(test, 100*time.Millisecond, cancel) - b, err := ioutil.ReadAll(tr) + b, err := io.ReadAll(tr) if err != nil || string(b) != "AAA" { t.Fatalf("Bad read %s %s", err, b) } @@ -81,7 +80,7 @@ func TestTimeoutReaderTimeout(t *testing.T) { cancelled = true } tr := newTimeoutReader(test, 10*time.Millisecond, cancel) - _, err := ioutil.ReadAll(tr) + _, err := io.ReadAll(tr) if err != TimeoutError { t.Fatal("Expecting TimeoutError, got", err) } diff --git a/watchdog_reader_test.go b/watchdog_reader_test.go index 43e44143f..214fad469 100644 --- a/watchdog_reader_test.go +++ b/watchdog_reader_test.go @@ -5,7 +5,6 @@ package swift import ( "bytes" "io" - "io/ioutil" "testing" "time" ) @@ -16,7 +15,7 @@ func testWatchdogReaderTimeout(t *testing.T, initialTimeout, watchdogTimeout tim test := newTestReader(3, 10*time.Millisecond) timer, firedChan := setupTimer(initialTimeout) wr := newWatchdogReader(test, watchdogTimeout, timer) - b, err := ioutil.ReadAll(wr) + b, err := io.ReadAll(wr) if err != nil || string(b) != "AAA" { t.Fatalf("Bad read %s %s", err, b) } @@ -99,7 +98,7 @@ func TestWatchdogReaderOnSlowNetwork(t *testing.T) { timer, firedChan := setupTimer(100 * time.Millisecond) wr := newWatchdogReader(reader, 190*time.Millisecond, timer) - //use io.ReadFull instead of ioutil.ReadAll here because ReadAll already does + //use io.ReadFull instead of io.ReadAll here because ReadAll already does //some chunking that would keep this testcase from failing b := make([]byte, len(byteString)) n, err := io.ReadFull(wr, b)