refactor: move from io/ioutil to io and os package (#2236)

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2021-10-23 17:14:12 +05:30
committed by GitHub
parent e641246866
commit 2f4ec4b2b9
40 changed files with 101 additions and 117 deletions
+1 -2
View File
@@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
@@ -101,7 +100,7 @@ func (c *Client) Upload(ctx context.Context, filePath string, metadata *map[stri
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
+8 -9
View File
@@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"testing"
@@ -50,7 +49,7 @@ func panicIf(err error) {
}
func MakeTestFile(size int) *os.File {
f, err := ioutil.TempFile("", "storagesvc_test_")
f, err := os.CreateTemp("", "storagesvc_test_")
panicIf(err)
_, err = f.Write(bytes.Repeat([]byte("."), size))
@@ -158,7 +157,7 @@ func TestS3StorageService(t *testing.T) {
panicIf(err)
defer reader.Close()
retThroughMinio, err := ioutil.TempFile("", "storagesvc_verify_minio_")
retThroughMinio, err := os.CreateTemp("", "storagesvc_verify_minio_")
panicIf(err)
defer os.Remove(retThroughMinio.Name())
@@ -170,7 +169,7 @@ func TestS3StorageService(t *testing.T) {
}
// Retrieve file through API
retThroughAPI, err := ioutil.TempFile("", "storagesvc_verify_")
retThroughAPI, err := os.CreateTemp("", "storagesvc_verify_")
panicIf(err)
os.Remove(retThroughAPI.Name())
@@ -179,9 +178,9 @@ func TestS3StorageService(t *testing.T) {
defer os.Remove(retThroughAPI.Name())
// compare contents
contentsMinio, err := ioutil.ReadFile(retThroughMinio.Name())
contentsMinio, err := os.ReadFile(retThroughMinio.Name())
panicIf(err)
contentsAPI, err := ioutil.ReadFile(retThroughAPI.Name())
contentsAPI, err := os.ReadFile(retThroughAPI.Name())
panicIf(err)
if !bytes.Equal(contentsMinio, contentsAPI) {
log.Panic("Contents don't match")
@@ -228,7 +227,7 @@ func TestLocalStorageService(t *testing.T) {
panicIf(err)
// make a temp file for verification
retrievedfile, err := ioutil.TempFile("", "storagesvc_verify_")
retrievedfile, err := os.CreateTemp("", "storagesvc_verify_")
panicIf(err)
os.Remove(retrievedfile.Name())
@@ -238,9 +237,9 @@ func TestLocalStorageService(t *testing.T) {
defer os.Remove(retrievedfile.Name())
// compare contents
contents1, err := ioutil.ReadFile(tmpfile.Name())
contents1, err := os.ReadFile(tmpfile.Name())
panicIf(err)
contents2, err := ioutil.ReadFile(retrievedfile.Name())
contents2, err := os.ReadFile(retrievedfile.Name())
panicIf(err)
if !bytes.Equal(contents1, contents2) {
log.Panic("Contents don't match")