Skip to content

Commit

Permalink
Replace deprecated ioutil.ReadAll with io.ReadAll
Browse files Browse the repository at this point in the history
This bumps the minimum go version from go1.15 to go1.16 as io.ReadAll
was only added in go1.16
  • Loading branch information
ncw committed Aug 29, 2024
1 parent 883590e commit 16e3ce8
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/ncw/swift/v2

go 1.15
go 1.16
4 changes: 2 additions & 2 deletions slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/url"
"os"
)
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"mime"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions swift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 4 additions & 5 deletions swifttest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"mime"
"net"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
5 changes: 2 additions & 3 deletions timeout_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package swift

import (
"io"
"io/ioutil"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions watchdog_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package swift
import (
"bytes"
"io"
"io/ioutil"
"testing"
"time"
)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 16e3ce8

Please sign in to comment.