golang: Stop using io/ioutils

The package has been deprecated as part of 1.16 and the same
functionality is now provided by either the io or the os package.

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio
2022-11-17 13:11:05 +01:00
parent 66aa330d0d
commit 16b8375095
16 changed files with 35 additions and 47 deletions

View File

@@ -14,7 +14,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httputil"
@@ -213,13 +213,13 @@ var vmAddNetPutRequest = func(clh *cloudHypervisor) error {
return err
}
respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
resp.Body.Close()
resp.Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
resp.Body = io.NopCloser(bytes.NewBuffer(respBody))
if resp.StatusCode != 204 {
clh.Logger().Errorf("vmAddNetPut failed with error '%d'. Response: %+v", resp.StatusCode, resp)

View File

@@ -10,7 +10,6 @@ package virtcontainers
import (
"context"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@@ -134,7 +133,7 @@ func TestCloudHypervisorAddNetCheckNetConfigListValues(t *testing.T) {
macTest := "00:00:00:00:00"
file, err := ioutil.TempFile("", "netFd")
file, err := os.CreateTemp("", "netFd")
assert.Nil(err)
defer os.Remove(file.Name())
@@ -172,7 +171,7 @@ func TestCloudHypervisorAddNetCheckEnpointTypes(t *testing.T) {
macTest := "00:00:00:00:00"
file, err := ioutil.TempFile("", "netFd")
file, err := os.CreateTemp("", "netFd")
assert.Nil(err)
defer os.Remove(file.Name())
@@ -214,7 +213,7 @@ func TestCloudHypervisorAddNetCheckEnpointTypes(t *testing.T) {
func TestCloudHypervisorNetRateLimiter(t *testing.T) {
assert := assert.New(t)
file, err := ioutil.TempFile("", "netFd")
file, err := os.CreateTemp("", "netFd")
assert.Nil(err)
defer os.Remove(file.Name())

View File

@@ -9,7 +9,6 @@ import (
"bufio"
"context"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@@ -1168,7 +1167,7 @@ func TestHandleHugepages(t *testing.T) {
// are present (default is 1M, can only be changed on LPAR). See
// https://www.ibm.com/docs/en/linuxonibm/pdf/lku5dd05.pdf, p. 345 for more information.
if runtime.GOARCH == "s390x" {
dirs, err := ioutil.ReadDir(sysHugepagesDir)
dirs, err := os.ReadDir(sysHugepagesDir)
assert.Nil(err)
for _, dir := range dirs {
formattedSizes = append(formattedSizes, strings.TrimPrefix(dir.Name(), "hugepages-"))

View File

@@ -13,7 +13,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
@@ -398,7 +397,7 @@ func (c *NydusClient) CheckStatus() (DaemonInfo, error) {
return DaemonInfo{}, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return DaemonInfo{}, err
}
@@ -470,7 +469,7 @@ func (c *NydusClient) Umount(mountPoint string) error {
}
func handleMountError(r io.Reader) error {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return err
}