refactor: move from io/ioutil to io and os packages (#5266)

The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-10-18 15:47:38 +08:00
committed by GitHub
parent 08b8069647
commit d1fec72a32
45 changed files with 113 additions and 127 deletions

View File

@@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
@@ -423,10 +422,10 @@ func validateKubeSphereAPIServer(config *rest.Config) (*version.Info, error) {
}
defer response.Body.Close()
responseBytes, _ := ioutil.ReadAll(response.Body)
responseBytes, _ := io.ReadAll(response.Body)
responseBody := string(responseBytes)
response.Body = ioutil.NopCloser(bytes.NewBuffer(responseBytes))
response.Body = io.NopCloser(bytes.NewBuffer(responseBytes))
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("invalid response: %s , please make sure %s.%s.svc of member cluster is up and running", KubeSphereApiServer, constants.KubeSphereNamespace, responseBody)

View File

@@ -21,7 +21,7 @@ package v1alpha3
import (
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
@@ -364,7 +364,7 @@ func (h handler) handleGrafanaDashboardImport(req *restful.Request, resp *restfu
defer r.Body.Close()
c, err := ioutil.ReadAll(r.Body)
c, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}

View File

@@ -18,7 +18,7 @@ package v1alpha2
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
@@ -54,7 +54,7 @@ func (h *handler) getNamespaceTopology(request *restful.Request, response *restf
return
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
klog.Errorf("read response error : %v", err)
@@ -86,7 +86,7 @@ func (h *handler) getNamespaceNodeTopology(request *restful.Request, response *r
return
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
klog.Errorf("read response error : %v", err)

View File

@@ -16,7 +16,7 @@
package v2beta2
import (
"io/ioutil"
"io"
"github.com/emicklei/go-restful"
"k8s.io/apimachinery/pkg/api/errors"
@@ -131,7 +131,7 @@ func (h *handler) PatchResource(req *restful.Request, resp *restful.Response) {
return
}
data, err := ioutil.ReadAll(req.Request.Body)
data, err := io.ReadAll(req.Request.Body)
if err != nil {
api.HandleBadRequest(resp, req, err)
return

View File

@@ -16,7 +16,7 @@ package v1
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"math"
"net/url"
"strconv"
@@ -987,7 +987,7 @@ func (h *openpitrixHandler) CreateAttachment(req *restful.Request, resp *restful
api.HandleBadRequest(resp, nil, err)
return
}
data, _ := ioutil.ReadAll(f)
data, _ := io.ReadAll(f)
f.Close()
att, err = h.openpitrix.CreateAttachment(data)

View File

@@ -20,7 +20,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"github.com/emicklei/go-restful"
@@ -172,7 +172,7 @@ func (h *Handler) getData(response *restful.Response, url string) {
return
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
@@ -202,7 +202,7 @@ func (h *Handler) getJaegerData(response *restful.Response, url string) {
return
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {