replace the ioutil by the os and io
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
parent
f68da6d64e
commit
1a6b35649c
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -116,7 +115,7 @@ func main() {
|
|||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import (
|
|||
"go/format"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -133,7 +132,7 @@ func (a *analyzer) collect(dir string) {
|
|||
panic(fmt.Sprintf("Error stat'ing file: %s\n%s\n", pathToFile, err.Error()))
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(pathToFile, buffer.Bytes(), fileInfo.Mode())
|
||||
err = os.WriteFile(pathToFile, buffer.Bytes(), fileInfo.Mode())
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Error writing file: %s\n%s\n", pathToFile, err.Error()))
|
||||
}
|
||||
|
@ -244,7 +243,7 @@ func main() {
|
|||
sort.Strings(c.dirs)
|
||||
|
||||
if len(*importAliases) > 0 {
|
||||
bytes, err := ioutil.ReadFile(*importAliases)
|
||||
bytes, err := os.ReadFile(*importAliases)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading import aliases: %v", err)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
@ -176,7 +176,7 @@ func createExtralResources(clientSet *kubernetes.Clientset, dir string) error {
|
|||
}
|
||||
|
||||
func crdPatchesResources(filename, caBundle string) ([]byte, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ func crdPatchesResources(filename, caBundle string) ([]byte, error) {
|
|||
// createCRDs create crd resource
|
||||
func createCRDs(crdClient *clientset.Clientset, filename string) error {
|
||||
obj := apiextensionsv1.CustomResourceDefinition{}
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package utils
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -60,7 +60,7 @@ func InternetIP() (net.IP, error) {
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
content, err := ioutil.ReadAll(resp.Body)
|
||||
content, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -262,7 +261,7 @@ func (o *CommandRegisterOption) Complete(args []string) error {
|
|||
}
|
||||
|
||||
if len(o.ClusterName) == 0 {
|
||||
configBytes, err := ioutil.ReadFile(o.KubeConfig)
|
||||
configBytes, err := os.ReadFile(o.KubeConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read kubeconfig file %s, err: %w", o.KubeConfig, err)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
@ -121,7 +120,7 @@ func modifyRequest(req *http.Request, cluster string) error {
|
|||
_ = req.Body.Close()
|
||||
|
||||
defer func() {
|
||||
req.Body = ioutil.NopCloser(body)
|
||||
req.Body = io.NopCloser(body)
|
||||
req.ContentLength = int64(body.Len())
|
||||
}()
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
|
@ -137,7 +136,7 @@ func TestModifyRequest(t *testing.T) {
|
|||
|
||||
var get runtime.Object
|
||||
if req.ContentLength != 0 {
|
||||
data, err := ioutil.ReadAll(req.Body)
|
||||
data, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -368,7 +367,7 @@ func Test_clusterProxy_connect(t *testing.T) {
|
|||
request: (&http.Request{
|
||||
Method: "PUT",
|
||||
URL: &url.URL{Scheme: "https", Host: "localhost", Path: "/test"},
|
||||
Body: ioutil.NopCloser(&alwaysErrorReader{}),
|
||||
Body: io.NopCloser(&alwaysErrorReader{}),
|
||||
ContentLength: 10,
|
||||
Header: make(http.Header),
|
||||
}).WithContext(reqCtx),
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -34,7 +33,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
defer r.Body.Close()
|
||||
if body, err = ioutil.ReadAll(r.Body); err != nil {
|
||||
if body, err = io.ReadAll(r.Body); err != nil {
|
||||
klog.Errorf("unable to read the body from the incoming request: %w", err)
|
||||
res = Errored(http.StatusBadRequest, err)
|
||||
wh.writeResponse(w, res)
|
||||
|
|
Loading…
Reference in New Issue