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:
@@ -22,7 +22,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -306,7 +305,7 @@ func (d devopsOperator) ListPipelineObj(projectName string, filterFunc PipelineF
|
||||
return api.ListResult{TotalItems: len(result), Items: items}, nil
|
||||
}
|
||||
|
||||
//credentialobj in crd
|
||||
// credentialobj in crd
|
||||
func (d devopsOperator) CreateCredentialObj(projectName string, secret *v1.Secret) (*v1.Secret, error) {
|
||||
projectObj, err := d.ksInformers.Devops().V1alpha3().DevOpsProjects().Lister().Get(projectName)
|
||||
if err != nil {
|
||||
@@ -837,7 +836,7 @@ func (d devopsOperator) GetOrgRepo(scmId, organizationId string, req *http.Reque
|
||||
// CreateSCMServers creates a Bitbucket server config item in Jenkins configuration if there's no same API address exist
|
||||
func (d devopsOperator) CreateSCMServers(scmId string, req *http.Request) (*devops.SCMServer, error) {
|
||||
|
||||
requestBody, err := ioutil.ReadAll(req.Body)
|
||||
requestBody, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
@@ -861,7 +860,7 @@ func (d devopsOperator) CreateSCMServers(scmId string, req *http.Request) (*devo
|
||||
return &server, nil
|
||||
}
|
||||
}
|
||||
req.Body = ioutil.NopCloser(bytes.NewReader(requestBody))
|
||||
req.Body = io.NopCloser(bytes.NewReader(requestBody))
|
||||
|
||||
req.Method = http.MethodPost
|
||||
resBody, err := d.devopsClient.CreateSCMServers(scmId, convertToHttpParameters(req))
|
||||
@@ -977,7 +976,7 @@ func getInputReqBody(reqBody io.ReadCloser) (newReqBody io.ReadCloser, err error
|
||||
Abort bool `json:"abort,omitempty" description:"abort or not"`
|
||||
}
|
||||
|
||||
Body, err := ioutil.ReadAll(reqBody)
|
||||
Body, err := io.ReadAll(reqBody)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
@@ -1002,7 +1001,7 @@ func getInputReqBody(reqBody io.ReadCloser) (newReqBody io.ReadCloser, err error
|
||||
func parseBody(body io.Reader) (newReqBody io.ReadCloser) {
|
||||
rc, ok := body.(io.ReadCloser)
|
||||
if !ok && body != nil {
|
||||
rc = ioutil.NopCloser(body)
|
||||
rc = io.NopCloser(body)
|
||||
}
|
||||
return rc
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
corev1listers "k8s.io/client-go/listers/core/v1"
|
||||
@@ -102,7 +102,7 @@ func (o *operator) CreateKubeConfig(user *iamv1alpha2.User) error {
|
||||
if len(o.config.CAData) > 0 {
|
||||
ca = o.config.CAData
|
||||
} else {
|
||||
ca, err = ioutil.ReadFile(inClusterCAFilePath)
|
||||
ca, err = os.ReadFile(inClusterCAFilePath)
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return err
|
||||
|
||||
@@ -18,8 +18,8 @@ package monitoring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -161,7 +161,7 @@ func jsonFromFile(sourceFile, expectedFile string) (*Metrics, *Metrics, error) {
|
||||
sourceJson := &Metrics{}
|
||||
expectedJson := &Metrics{}
|
||||
|
||||
json, err := ioutil.ReadFile(fmt.Sprintf("./testdata/%s", sourceFile))
|
||||
json, err := os.ReadFile(fmt.Sprintf("./testdata/%s", sourceFile))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func jsonFromFile(sourceFile, expectedFile string) (*Metrics, *Metrics, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
json, err = ioutil.ReadFile(fmt.Sprintf("./testdata/%s", expectedFile))
|
||||
json, err = os.ReadFile(fmt.Sprintf("./testdata/%s", expectedFile))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
@@ -524,7 +523,7 @@ func (o *operator) Verify(request *restful.Request, response *restful.Response)
|
||||
return
|
||||
}
|
||||
|
||||
reqBody, err := ioutil.ReadAll(request.Request.Body)
|
||||
reqBody, err := io.ReadAll(request.Request.Body)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
_ = response.WriteHeaderAndEntity(http.StatusBadRequest, err)
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
@@ -179,7 +178,7 @@ func GetRespBody(resp *http.Response) ([]byte, error) {
|
||||
} else {
|
||||
reader = resp.Body
|
||||
}
|
||||
resBody, err := ioutil.ReadAll(reader)
|
||||
resBody, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
|
||||
@@ -19,7 +19,7 @@ package routers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -170,7 +170,7 @@ func (c *routerOperator) getRouterService(namespace string) (*corev1.Service, er
|
||||
// Load all resource yamls
|
||||
func loadYamls() ([]string, error) {
|
||||
var yamls []string
|
||||
files, err := ioutil.ReadDir(ingressControllerFolder)
|
||||
files, err := os.ReadDir(ingressControllerFolder)
|
||||
if err != nil {
|
||||
klog.Warning(err)
|
||||
return nil, err
|
||||
@@ -180,7 +180,7 @@ func loadYamls() ([]string, error) {
|
||||
if file.IsDir() || !strings.HasSuffix(file.Name(), ".yaml") {
|
||||
continue
|
||||
}
|
||||
content, err := ioutil.ReadFile(ingressControllerFolder + "/" + file.Name())
|
||||
content, err := os.ReadFile(ingressControllerFolder + "/" + file.Name())
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user