replace deprecated io/ioutil with os and io for cmd

This commit is contained in:
ahrtr
2021-11-02 08:54:28 +08:00
parent 6dd234d85c
commit 972dc46a1f
73 changed files with 187 additions and 239 deletions

View File

@@ -18,7 +18,7 @@ package app
import (
"errors"
"io/ioutil"
"os"
"strconv"
"strings"
@@ -132,7 +132,7 @@ func isSysFSWritable() (bool, error) {
}
func readIntStringFile(filename string) (int, error) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return -1, err
}
@@ -140,5 +140,5 @@ func readIntStringFile(filename string) (int, error) {
}
func writeIntStringFile(filename string, value int) error {
return ioutil.WriteFile(filename, []byte(strconv.Itoa(value)), 0640)
return os.WriteFile(filename, []byte(strconv.Itoa(value)), 0640)
}

View File

@@ -22,7 +22,6 @@ import (
"errors"
goflag "flag"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
@@ -403,7 +402,7 @@ func newLenientSchemeAndCodecs() (*runtime.Scheme, *serializer.CodecFactory, err
// loadConfigFromFile loads the contents of file and decodes it as a
// KubeProxyConfiguration object.
func (o *Options) loadConfigFromFile(file string) (*kubeproxyconfig.KubeProxyConfiguration, error) {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
return nil, err
}

View File

@@ -19,7 +19,6 @@ package app
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@@ -406,7 +405,7 @@ func TestProcessHostnameOverrideFlag(t *testing.T) {
func TestConfigChange(t *testing.T) {
setUp := func() (*os.File, string, error) {
tempDir, err := ioutil.TempDir("", "kubeproxy-config-change")
tempDir, err := os.MkdirTemp("", "kubeproxy-config-change")
if err != nil {
return nil, "", fmt.Errorf("unable to create temporary directory: %v", err)
}