From 8bfce9b43ebe4f57aa5a68540f9757d7fe442c0e Mon Sep 17 00:00:00 2001 From: wusphinx Date: Mon, 25 Sep 2023 23:32:11 +0800 Subject: [PATCH] chore: convert ioutil to io and os (#1151) --- .../elastic/beats/v7/libbeat/logp/core.go | 6 +++--- helper/envconfig/aliyun_ecs_meta_data.go | 8 ++++---- pkg/doc/generate.go | 5 ++--- pkg/doc/generate_test.go | 3 +-- pkg/helper/docker_center_file_discover.go | 5 ++--- .../docker_center_file_discover_test.go | 19 +++++++++---------- pkg/helper/docker_center_test.go | 5 ++--- pkg/helper/dumper_test.go | 3 +-- pkg/helper/platformmeta/aliyun_ecs.go | 4 ++-- pkg/helper/profile/pyroscope/jfr/jfr_test.go | 5 ++--- pkg/protocol/decoder/common/comon.go | 5 ++--- .../decoder/pyroscope/decoder_test.go | 4 ++-- pkg/util/util.go | 3 +-- plugin_main/flags/flags.go | 8 ++++---- plugin_main/plugin_http.go | 3 +-- pluginmanager/logtail_port_manager.go | 3 +-- pluginmanager/plugin_manager_test.go | 4 ++-- .../flusher/elasticsearch/authentication.go | 4 ++-- plugins/flusher/http/flusher_http.go | 4 ++-- plugins/flusher/http/flusher_http_test.go | 12 ++++++------ .../stdout/docker_stdout_processor_test.go | 4 ++-- plugins/input/http/input_http.go | 5 ++--- .../httpserver/input_http_server_test.go | 6 +++--- plugins/input/jmxfetch/jmxfetchd.go | 4 ++-- plugins/input/jmxfetch/manager.go | 5 ++--- plugins/input/jmxfetch/manager_test.go | 4 ++-- plugins/input/mockd/input_mockd.go | 4 ++-- plugins/input/mysql/mysql.go | 4 ++-- plugins/input/netping/netping.go | 4 ++-- plugins/input/prometheus/input_prometheus.go | 4 ++-- plugins/input/rdb/rdb.go | 4 ++-- .../skywalkingv3/jvm_metric_handle_test.go | 4 ++-- plugins/input/systemv2/input_system_linux.go | 4 ++-- plugins/input/telegraf/telegraf_manager.go | 7 +++---- .../input/telegraf/telegraf_manager_test.go | 13 ++++++------- .../processor/encrypt/processor_encrypt.go | 4 ++-- .../encrypt/processor_encrypt_test.go | 8 ++++---- plugins/test/common.go | 4 ++-- .../behavior/input_observer_http/mock/main.go | 3 +-- tools/builder/main.go | 10 +++++----- tools/builder/main_test.go | 6 +++--- 41 files changed, 104 insertions(+), 120 deletions(-) diff --git a/external/github.com/elastic/beats/v7/libbeat/logp/core.go b/external/github.com/elastic/beats/v7/libbeat/logp/core.go index 7b33593711..22952b24dd 100644 --- a/external/github.com/elastic/beats/v7/libbeat/logp/core.go +++ b/external/github.com/elastic/beats/v7/libbeat/logp/core.go @@ -19,7 +19,7 @@ package logp import ( "flag" - "io/ioutil" + "io" golog "log" "os" "path/filepath" @@ -100,7 +100,7 @@ func Configure(cfg Config) error { if _, enabled := selectors["stdlog"]; !enabled { // Disable standard logging by default (this is sometimes used by // libraries and we don't want their spam). - golog.SetOutput(ioutil.Discard) + golog.SetOutput(io.Discard) } sink = selectiveWrapper(sink, selectors) @@ -172,7 +172,7 @@ func makeStderrOutput(cfg Config) (zapcore.Core, error) { } func makeDiscardOutput(cfg Config) (zapcore.Core, error) { - discard := zapcore.AddSync(ioutil.Discard) + discard := zapcore.AddSync(io.Discard) return zapcore.NewCore(buildEncoder(cfg), discard, cfg.Level.zapLevel()), nil } diff --git a/helper/envconfig/aliyun_ecs_meta_data.go b/helper/envconfig/aliyun_ecs_meta_data.go index 28b2dc0511..0e69ca37b6 100644 --- a/helper/envconfig/aliyun_ecs_meta_data.go +++ b/helper/envconfig/aliyun_ecs_meta_data.go @@ -21,7 +21,7 @@ import ( "encoding/base64" "encoding/json" "errors" - "io/ioutil" + "io" "net/http" "os" "path/filepath" @@ -76,7 +76,7 @@ func getToken() (result []byte, err error) { } defer respList.Body.Close() var body []byte - body, err = ioutil.ReadAll(respList.Body) + body, err = io.ReadAll(respList.Body) if err != nil { logger.Warning(context.Background(), "UPDATE_STS_ALARM", "parse role list error", err) return nil, err @@ -96,7 +96,7 @@ func getToken() (result []byte, err error) { return nil, err } defer respGet.Body.Close() - body, err = ioutil.ReadAll(respGet.Body) + body, err = io.ReadAll(respGet.Body) if err != nil { logger.Warning(context.Background(), "UPDATE_STS_ALARM", "parse token error", err, "role", role) return nil, err @@ -156,7 +156,7 @@ func getAKFromLocalFile() (accessKeyID, accessKeySecret, securityToken string, e if err == nil { var akInfo AKInfo // 获取token config json - encodeTokenCfg, err := ioutil.ReadFile(filepath.Clean(addonTokenConfigPath)) + encodeTokenCfg, err := os.ReadFile(filepath.Clean(addonTokenConfigPath)) if err != nil { return accessKeyID, accessKeySecret, securityToken, expireTime, err } diff --git a/pkg/doc/generate.go b/pkg/doc/generate.go index 22b6489401..801c0ca461 100644 --- a/pkg/doc/generate.go +++ b/pkg/doc/generate.go @@ -17,7 +17,6 @@ package doc import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -66,7 +65,7 @@ func Generate(path string) { str += " - [" + name + "](" + relativeFile + ")" + lf } } - _ = ioutil.WriteFile(fileName, []byte(str), 0600) + _ = os.WriteFile(fileName, []byte(str), 0600) } func generatePluginDoc(fileName, pluginName string, doc Doc) { @@ -81,7 +80,7 @@ func generatePluginDoc(fileName, pluginName string, doc Doc) { str += lf + tableSplitor + config.Name + tableSplitor + config.Type + tableSplitor + config.Comment + tableSplitor + config.Default + tableSplitor } } - _ = ioutil.WriteFile(fileName, []byte(str), 0600) + _ = os.WriteFile(fileName, []byte(str), 0600) } func extractDocConfig(doc Doc) (configs []*FieldConfig) { diff --git a/pkg/doc/generate_test.go b/pkg/doc/generate_test.go index 6a9fa0af26..20b83f0a52 100644 --- a/pkg/doc/generate_test.go +++ b/pkg/doc/generate_test.go @@ -15,7 +15,6 @@ package doc import ( - "io/ioutil" "os" "testing" @@ -95,7 +94,7 @@ this is a test doc demo "k": "v", } generatePluginDoc("test-plugin.md", "test-plugin", t2) - bytes, _ := ioutil.ReadFile("test-plugin.md") + bytes, _ := os.ReadFile("test-plugin.md") assert.Equal(t, str, string(bytes)) _ = os.Remove("test-plugin.md") } diff --git a/pkg/helper/docker_center_file_discover.go b/pkg/helper/docker_center_file_discover.go index 33bc34af26..37534ade59 100644 --- a/pkg/helper/docker_center_file_discover.go +++ b/pkg/helper/docker_center_file_discover.go @@ -19,7 +19,6 @@ import ( "encoding/json" "fmt" "io/fs" - "io/ioutil" "os" "path/filepath" "strconv" @@ -170,7 +169,7 @@ func scanContainerdFilesAndReLink(filePath string) { } for { time.Sleep(time.Millisecond * time.Duration(containerdScanIntervalMs)) - dir, err := ioutil.ReadDir(dirPath) + dir, err := os.ReadDir(dirPath) if err != nil { continue } @@ -204,7 +203,7 @@ func scanContainerdFilesAndReLink(filePath string) { } func innerReadStatisContainerInfo(file string, lastContainerInfo []types.ContainerJSON, stat fs.FileInfo) (containers []types.ContainerJSON, removed []string, changed bool, err error) { - body, err := ioutil.ReadFile(filepath.Clean(file)) + body, err := os.ReadFile(filepath.Clean(file)) if err != nil { return nil, nil, false, err } diff --git a/pkg/helper/docker_center_file_discover_test.go b/pkg/helper/docker_center_file_discover_test.go index 24a22ad415..6bc1a20e4e 100644 --- a/pkg/helper/docker_center_file_discover_test.go +++ b/pkg/helper/docker_center_file_discover_test.go @@ -19,7 +19,6 @@ package helper import ( "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -698,7 +697,7 @@ var staticECIConfig2 = `[ func TestTryReadStaticContainerInfo(t *testing.T) { defer os.Remove("./static_container.json") defer os.Unsetenv(staticContainerInfoPathEnvKey) - ioutil.WriteFile("./static_container.json", []byte(staticDockerConfig), os.ModePerm) + os.WriteFile("./static_container.json", []byte(staticDockerConfig), os.ModePerm) os.Setenv(staticContainerInfoPathEnvKey, "./static_container.json") containerInfo, removedIDs, changed, err := tryReadStaticContainerInfo() require.Nil(t, err) @@ -724,7 +723,7 @@ func TestTryReadStaticContainerInfo(t *testing.T) { } require.Equal(t, 999999999908, info.State.Pid) - ioutil.WriteFile("./static_container.json", []byte(staticDockerConfig2), os.ModePerm) + os.WriteFile("./static_container.json", []byte(staticDockerConfig2), os.ModePerm) containerInfo, removedIDs, changed, err = tryReadStaticContainerInfo() require.Nil(t, err) @@ -751,7 +750,7 @@ func TestLoadStaticContainerConfig(t *testing.T) { resetDockerCenter() defer os.Remove("./static_container.json") defer os.Unsetenv(staticContainerInfoPathEnvKey) - ioutil.WriteFile("./static_container.json", []byte(staticDockerConfig), os.ModePerm) + os.WriteFile("./static_container.json", []byte(staticDockerConfig), os.ModePerm) os.Setenv(staticContainerInfoPathEnvKey, "./static_container.json") instance := getDockerCenterInstance() allInfo := instance.containerMap @@ -766,7 +765,7 @@ func TestLoadStaticContainerConfigTwice(t *testing.T) { resetDockerCenter() defer os.Remove("./static_container.json") defer os.Unsetenv(staticContainerInfoPathEnvKey) - ioutil.WriteFile("./static_container.json", []byte(staticECIConfig), os.ModePerm) + os.WriteFile("./static_container.json", []byte(staticECIConfig), os.ModePerm) os.Setenv(staticContainerInfoPathEnvKey, "./static_container.json") instance := getDockerCenterInstance() allInfo := instance.containerMap @@ -776,7 +775,7 @@ func TestLoadStaticContainerConfigTwice(t *testing.T) { } os.Remove("./static_container.json") - ioutil.WriteFile("./static_container.json", []byte(staticECIConfig2), os.ModePerm) + os.WriteFile("./static_container.json", []byte(staticECIConfig2), os.ModePerm) time.Sleep(time.Second * 10) @@ -814,18 +813,18 @@ func TestScanContainerdFilesAndReLink(t *testing.T) { go scanContainerdFilesAndReLink(logName) time.Sleep(time.Second) - ioutil.WriteFile(filepath.Join(dir, "0.log"), []byte("abc"), os.ModePerm) + os.WriteFile(filepath.Join(dir, "0.log"), []byte("abc"), os.ModePerm) checkSameDevInode(t, logName, filepath.Join(dir, "0.log")) - ioutil.WriteFile(filepath.Join(dir, "99.log"), []byte("abcdef"), os.ModePerm) + os.WriteFile(filepath.Join(dir, "99.log"), []byte("abcdef"), os.ModePerm) time.Sleep(time.Second * 2) checkSameDevInode(t, logName, filepath.Join(dir, "99.log")) - ioutil.WriteFile(filepath.Join(dir, "100.log"), []byte("abcde"), os.ModePerm) + os.WriteFile(filepath.Join(dir, "100.log"), []byte("abcde"), os.ModePerm) time.Sleep(time.Second * 2) checkSameDevInode(t, logName, filepath.Join(dir, "100.log")) - ioutil.WriteFile(filepath.Join(dir, "101.log"), []byte("abcdefg"), os.ModePerm) + os.WriteFile(filepath.Join(dir, "101.log"), []byte("abcdefg"), os.ModePerm) time.Sleep(time.Second * 2) checkSameDevInode(t, logName, filepath.Join(dir, "101.log")) } diff --git a/pkg/helper/docker_center_test.go b/pkg/helper/docker_center_test.go index f67b0f460a..78678eb37d 100644 --- a/pkg/helper/docker_center_test.go +++ b/pkg/helper/docker_center_test.go @@ -15,7 +15,6 @@ package helper import ( - "io/ioutil" "os" "sync" "testing" @@ -55,7 +54,7 @@ func resetDockerCenter() { func TestGetIpByHost_1(t *testing.T) { hostFileName := "./tmp_TestGetIpByHost.txt" - ioutil.WriteFile(hostFileName, []byte(hostFileContent1), 0x777) + os.WriteFile(hostFileName, []byte(hostFileContent1), 0x777) ip := getIPByHosts(hostFileName, "8be13ee0dd9e") if ip != "192.168.5.3" { t.Errorf("GetIpByHosts = %v, want %v", ip, "192.168.5.3") @@ -65,7 +64,7 @@ func TestGetIpByHost_1(t *testing.T) { func TestGetIpByHost_2(t *testing.T) { hostFileName := "./tmp_TestGetIpByHost.txt" - ioutil.WriteFile(hostFileName, []byte(hostFileContent2), 0x777) + os.WriteFile(hostFileName, []byte(hostFileContent2), 0x777) ip := getIPByHosts(hostFileName, "nginx-5fd7568b67-4sh8c") if ip != "172.20.4.5" { t.Errorf("GetIpByHosts = %v, want %v", ip, "172.20.4.5") diff --git a/pkg/helper/dumper_test.go b/pkg/helper/dumper_test.go index 6e9f1a5499..3c48168dd1 100644 --- a/pkg/helper/dumper_test.go +++ b/pkg/helper/dumper_test.go @@ -19,7 +19,6 @@ import ( "encoding/binary" "encoding/json" "fmt" - "io/ioutil" "os" "path" "strconv" @@ -60,7 +59,7 @@ func TestServiceHTTP_doDumpFile(t *testing.T) { } } readFunc := func(file string, expectLen int) { - data, rerr := ioutil.ReadFile(file) + data, rerr := os.ReadFile(file) require.NoError(t, rerr) offset := 0 num := 0 diff --git a/pkg/helper/platformmeta/aliyun_ecs.go b/pkg/helper/platformmeta/aliyun_ecs.go index 52ae865e5f..7b19409930 100644 --- a/pkg/helper/platformmeta/aliyun_ecs.go +++ b/pkg/helper/platformmeta/aliyun_ecs.go @@ -17,7 +17,7 @@ package platformmeta import ( "context" "errors" - "io/ioutil" + "io" "net/http" "strconv" "strings" @@ -50,7 +50,7 @@ func AlibabaCloudEcsPlatformRequest(api string, method string, f func(header *ht if resp.StatusCode == 404 { return "", error404 } - bytes, err := ioutil.ReadAll(resp.Body) + bytes, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/pkg/helper/profile/pyroscope/jfr/jfr_test.go b/pkg/helper/profile/pyroscope/jfr/jfr_test.go index 8e2b6096d0..ae37279aff 100644 --- a/pkg/helper/profile/pyroscope/jfr/jfr_test.go +++ b/pkg/helper/profile/pyroscope/jfr/jfr_test.go @@ -19,7 +19,6 @@ import ( "compress/gzip" "context" "io" - "io/ioutil" "os" "testing" "time" @@ -106,7 +105,7 @@ func readGzipFile(fname string) ([]byte, error) { return nil, err } defer r.Close() - return ioutil.ReadAll(r) + return io.ReadAll(r) } func readRawFile(fname string) ([]byte, error) { @@ -115,5 +114,5 @@ func readRawFile(fname string) ([]byte, error) { return nil, err } defer f.Close() - return ioutil.ReadAll(f) + return io.ReadAll(f) } diff --git a/pkg/protocol/decoder/common/comon.go b/pkg/protocol/decoder/common/comon.go index 3f22903580..0386daf9df 100644 --- a/pkg/protocol/decoder/common/comon.go +++ b/pkg/protocol/decoder/common/comon.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strconv" "sync" @@ -89,7 +88,7 @@ func CollectBody(res http.ResponseWriter, req *http.Request, maxBodySize int64) return data, http.StatusOK, nil } - bytes, err := ioutil.ReadAll(body) + bytes, err := io.ReadAll(body) if err != nil { return nil, http.StatusRequestEntityTooLarge, err } @@ -112,7 +111,7 @@ func CollectBody(res http.ResponseWriter, req *http.Request, maxBodySize int64) func CollectRawBody(res http.ResponseWriter, req *http.Request, maxBodySize int64) ([]byte, int, error) { body := req.Body body = http.MaxBytesReader(res, body, maxBodySize) - bytes, err := ioutil.ReadAll(body) + bytes, err := io.ReadAll(body) if err != nil { return nil, http.StatusRequestEntityTooLarge, err } diff --git a/pkg/protocol/decoder/pyroscope/decoder_test.go b/pkg/protocol/decoder/pyroscope/decoder_test.go index ea674e2e12..dac871445f 100644 --- a/pkg/protocol/decoder/pyroscope/decoder_test.go +++ b/pkg/protocol/decoder/pyroscope/decoder_test.go @@ -18,8 +18,8 @@ import ( "bytes" "encoding/binary" "encoding/json" - "io/ioutil" "net/http" + "os" "sort" "testing" @@ -82,7 +82,7 @@ func TestDecoder_DecodeTire(t *testing.T) { } func TestDecoder_DecodePprofCumulative(t *testing.T) { - data, err := ioutil.ReadFile("test/dump_pprof_mem_data") + data, err := os.ReadFile("test/dump_pprof_mem_data") require.NoError(t, err) var length uint32 buffer := bytes.NewBuffer(data) diff --git a/pkg/util/util.go b/pkg/util/util.go index 4e9c96923e..05e52e4564 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -24,7 +24,6 @@ import ( "errors" "fmt" "hash/fnv" - "io/ioutil" "log" "os" "os/exec" @@ -122,7 +121,7 @@ func GetTLSConfig(sslCert, sslKey, sslCA string, insecureSkipVerify bool) (*tls. t := &tls.Config{InsecureSkipVerify: insecureSkipVerify} //nolint:gosec if sslCA != "" { - caCert, err := ioutil.ReadFile(filepath.Clean(sslCA)) + caCert, err := os.ReadFile(filepath.Clean(sslCA)) if err != nil { return nil, fmt.Errorf("Could not load TLS CA: %v", err) } diff --git a/plugin_main/flags/flags.go b/plugin_main/flags/flags.go index 355bdc8c4f..511da83cb2 100644 --- a/plugin_main/flags/flags.go +++ b/plugin_main/flags/flags.go @@ -19,7 +19,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "os" "sync" "github.com/alibaba/ilogtail/pkg/logger" @@ -62,7 +62,7 @@ var ( // LoadConfig read the plugin content. func LoadConfig() (globalCfg string, pluginCfgs []string, err error) { - if gCfg, errRead := ioutil.ReadFile(*GlobalConfig); errRead != nil { + if gCfg, errRead := os.ReadFile(*GlobalConfig); errRead != nil { globalCfg = defaultGlobalConfig } else { globalCfg = string(gCfg) @@ -74,7 +74,7 @@ func LoadConfig() (globalCfg string, pluginCfgs []string, err error) { } var pluginCfg string - if pCfg, errRead := ioutil.ReadFile(*PluginConfig); errRead == nil { + if pCfg, errRead := os.ReadFile(*PluginConfig); errRead == nil { pluginCfg = string(pCfg) } else { pluginCfg = defaultPluginConfig @@ -118,7 +118,7 @@ func GetFlusherConfiguration() (flusherCategory string, flusherOptions map[strin } return c, options, true } - if fCfg, err := ioutil.ReadFile(*FlusherConfig); err == nil { + if fCfg, err := os.ReadFile(*FlusherConfig); err == nil { category, options, ok := extract(fCfg) if ok { flusherType = category diff --git a/plugin_main/plugin_http.go b/plugin_main/plugin_http.go index db66ba1bf8..13328c8472 100644 --- a/plugin_main/plugin_http.go +++ b/plugin_main/plugin_http.go @@ -17,7 +17,6 @@ package main import ( "context" "io" - "io/ioutil" "net/http" _ "net/http/pprof" //nolint "os" @@ -98,7 +97,7 @@ func HelpServer(w http.ResponseWriter, req *http.Request) { func HandleLoadConfig(w http.ResponseWriter, r *http.Request) { controlLock.Lock() defer controlLock.Unlock() - bytes, err := ioutil.ReadAll(r.Body) + bytes, err := io.ReadAll(r.Body) if err != nil { logger.Error(context.Background(), "LOAD_CONFIG_ALARM", "stage", "read", "err", err) w.WriteHeader(500) diff --git a/pluginmanager/logtail_port_manager.go b/pluginmanager/logtail_port_manager.go index e73bb3f046..f10bf2aae1 100644 --- a/pluginmanager/logtail_port_manager.go +++ b/pluginmanager/logtail_port_manager.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -39,7 +38,7 @@ func getListenPortsFromFile(pid int, protocol string) ([]int, error) { ports := []int{} filepath.Join() file := fmt.Sprintf("/proc/%d/net/%s", pid, protocol) - data, err := ioutil.ReadFile(filepath.Clean(file)) + data, err := os.ReadFile(filepath.Clean(file)) if err != nil { return ports, err } diff --git a/pluginmanager/plugin_manager_test.go b/pluginmanager/plugin_manager_test.go index b90aca9a3e..960a84cb26 100644 --- a/pluginmanager/plugin_manager_test.go +++ b/pluginmanager/plugin_manager_test.go @@ -19,7 +19,7 @@ package pluginmanager import ( "context" - "io/ioutil" + "os" "testing" "time" @@ -91,7 +91,7 @@ func (s *managerTestSuite) TestPluginManager() { func GetTestConfig(configName string) string { fileName := "./test_config/" + configName + ".json" - byteStr, err := ioutil.ReadFile(fileName) + byteStr, err := os.ReadFile(fileName) if err != nil { logger.Warning(context.Background(), "read", fileName, "error", err) } diff --git a/plugins/flusher/elasticsearch/authentication.go b/plugins/flusher/elasticsearch/authentication.go index 164e087bab..51ec9d97e0 100644 --- a/plugins/flusher/elasticsearch/authentication.go +++ b/plugins/flusher/elasticsearch/authentication.go @@ -16,8 +16,8 @@ package elasticsearch import ( "fmt" - "io/ioutil" "net/http" + "os" "reflect" "time" @@ -79,7 +79,7 @@ func configureTLS(config *tlscommon.TLSConfig, opts *elasticsearch.Config) error transport.TLSClientConfig = tlsConfig } if config.CAFile != "" { - opts.CACert, err = ioutil.ReadFile(config.CAFile) + opts.CACert, err = os.ReadFile(config.CAFile) if err != nil { return err } diff --git a/plugins/flusher/http/flusher_http.go b/plugins/flusher/http/flusher_http.go index c7d51db9aa..e2641448db 100644 --- a/plugins/flusher/http/flusher_http.go +++ b/plugins/flusher/http/flusher_http.go @@ -19,7 +19,7 @@ import ( "crypto/rand" "errors" "fmt" - "io/ioutil" + "io" "math/big" "net/http" "net/url" @@ -384,7 +384,7 @@ func (f *FlusherHTTP) flush(data []byte, varValues map[string]string) (ok, retry logger.Error(f.context.GetRuntimeContext(), "FLUSHER_FLUSH_ALRAM", "http flusher send request fail, error", err) return false, retry, err } - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) if err != nil { logger.Error(f.context.GetRuntimeContext(), "FLUSHER_FLUSH_ALRAM", "http flusher read response fail, error", err) return false, false, err diff --git a/plugins/flusher/http/flusher_http_test.go b/plugins/flusher/http/flusher_http_test.go index 5ccc6295d5..d1a36baf7c 100644 --- a/plugins/flusher/http/flusher_http_test.go +++ b/plugins/flusher/http/flusher_http_test.go @@ -17,7 +17,7 @@ package http import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "sort" "testing" @@ -134,7 +134,7 @@ func TestHttpFlusherFlush(t *testing.T) { httpmock.RegisterResponder("POST", "http://test.com/write?db=mydb", func(req *http.Request) (*http.Response, error) { assert.Equal(t, "mydb", req.Header.Get("db")) - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) actualRequests = append(actualRequests, string(body)) return httpmock.NewStringResponse(200, "ok"), nil }) @@ -236,7 +236,7 @@ func TestHttpFlusherFlush(t *testing.T) { defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("POST", "http://test.com/write?db=mydb", func(req *http.Request) (*http.Response, error) { - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) actualRequests = append(actualRequests, string(body)) return httpmock.NewStringResponse(200, "ok"), nil }) @@ -339,7 +339,7 @@ func TestHttpFlusherFlushWithAuthenticator(t *testing.T) { httpmock.RegisterResponder("POST", "http://test.com/write?db=mydb", func(req *http.Request) (*http.Response, error) { assert.Equal(t, req.Header.Get("Authorization"), "Basic dXNlcjE6cHdkMQ==") - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) actualRequests = append(actualRequests, string(body)) return httpmock.NewStringResponse(200, "ok"), nil }) @@ -444,7 +444,7 @@ func TestHttpFlusherExport(t *testing.T) { defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("POST", "http://test.com/write?db=mydb", func(req *http.Request) (*http.Response, error) { - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) actualRequests = append(actualRequests, string(body)) return httpmock.NewStringResponse(200, "ok"), nil }) @@ -525,7 +525,7 @@ func TestHttpFlusherExport(t *testing.T) { defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("POST", "http://test.com/write?db=mydb", func(req *http.Request) (*http.Response, error) { - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) actualRequests = append(actualRequests, string(body)) return httpmock.NewStringResponse(200, "ok"), nil }) diff --git a/plugins/input/docker/stdout/docker_stdout_processor_test.go b/plugins/input/docker/stdout/docker_stdout_processor_test.go index 5ac7c63614..38399528a7 100644 --- a/plugins/input/docker/stdout/docker_stdout_processor_test.go +++ b/plugins/input/docker/stdout/docker_stdout_processor_test.go @@ -16,7 +16,7 @@ package stdout import ( "fmt" - "io/ioutil" + "os" "regexp" "strings" "testing" @@ -412,7 +412,7 @@ func (s *inputProcessorTestSuite) TestMultiLineError(c *check.C) { } func (s *inputProcessorTestSuite) TestBigLine(c *check.C) { - bigline, _ := ioutil.ReadFile("./big_data.json") + bigline, _ := os.ReadFile("./big_data.json") if len(bigline) == 0 { return } diff --git a/plugins/input/http/input_http.go b/plugins/input/http/input_http.go index 3a644b7cfb..0ce12729b2 100644 --- a/plugins/input/http/input_http.go +++ b/plugins/input/http/input_http.go @@ -18,7 +18,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -247,14 +246,14 @@ func (h *Response) httpGather(address string) (map[string]string, error) { } } defer func() { - _, _ = io.Copy(ioutil.Discard, resp.Body) + _, _ = io.Copy(io.Discard, resp.Body) _ = resp.Body.Close() }() fields["_response_time_ms_"] = strconv.FormatFloat(float64(time.Since(start).Nanoseconds())/1000000., 'f', 3, 32) fields["_http_response_code_"] = strconv.Itoa(resp.StatusCode) - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { logger.Error(h.context.GetRuntimeContext(), "HTTP_PARSE_ALARM", "Read body of HTTP response failed", err) fields["_result_"] = "invalid_body" diff --git a/plugins/input/httpserver/input_http_server_test.go b/plugins/input/httpserver/input_http_server_test.go index 9017ec0599..1f4aebf5ce 100644 --- a/plugins/input/httpserver/input_http_server_test.go +++ b/plugins/input/httpserver/input_http_server_test.go @@ -18,7 +18,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net" "net/http" "syscall" @@ -212,7 +212,7 @@ func sendRequest(bodyToSend string, port int) error { fmt.Println("response Status:", resp.Status) fmt.Println("response Headers:", resp.Header) - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) fmt.Println("response Body:", string(body)) return nil } @@ -345,7 +345,7 @@ func sendRequestWithParams(bodyToSend string, port int, headers map[string]strin fmt.Println("response Status:", resp.Status) fmt.Println("response Headers:", resp.Header) - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) fmt.Println("response Body:", string(body)) return nil } diff --git a/plugins/input/jmxfetch/jmxfetchd.go b/plugins/input/jmxfetch/jmxfetchd.go index e988b81bf4..8448ac718d 100644 --- a/plugins/input/jmxfetch/jmxfetchd.go +++ b/plugins/input/jmxfetch/jmxfetchd.go @@ -16,7 +16,7 @@ package jmxfetch import ( "fmt" - "io/ioutil" + "os" "os/exec" "strings" @@ -32,7 +32,7 @@ func (m *Manager) installScripts(javaPath string) error { yamls = append(yamls, key+".yaml") } scripts := fmt.Sprintf(scriptsTemplate, javaPath, strings.Join(yamls, ","), "0.0.0.0", m.port) - err := ioutil.WriteFile(m.jmxfetchdPath, []byte(scripts), 0755) //nolint: gosec + err := os.WriteFile(m.jmxfetchdPath, []byte(scripts), 0755) //nolint: gosec if err != nil { return fmt.Errorf("cannot crate jmxfetchd scripts: %v", err) } diff --git a/plugins/input/jmxfetch/manager.go b/plugins/input/jmxfetch/manager.go index 532e2b4631..af886098ed 100644 --- a/plugins/input/jmxfetch/manager.go +++ b/plugins/input/jmxfetch/manager.go @@ -16,7 +16,6 @@ package jmxfetch import ( "fmt" - "io/ioutil" "os" "os/exec" "path" @@ -300,7 +299,7 @@ func (m *Manager) updateFiles(key string, userCfg *Cfg) { } cfgPath := path.Join(m.jmxfetchConfPath, key+".yaml") logger.Debug(m.managerMeta.GetContext(), "write files", string(bytes), "path", cfgPath) - err = ioutil.WriteFile(cfgPath, bytes, 0600) + err = os.WriteFile(cfgPath, bytes, 0600) if err != nil { logger.Error(m.managerMeta.GetContext(), JMXAlarmType, "write config file err", err, "path", cfgPath) } @@ -389,7 +388,7 @@ func (m *Manager) initConfDir() bool { return true } // Clean config files (outdated) in conf directory. - if files, err := ioutil.ReadDir(m.jmxfetchConfPath); err == nil { + if files, err := os.ReadDir(m.jmxfetchConfPath); err == nil { for _, f := range files { filePath := path.Join(m.jmxfetchConfPath, f.Name()) if err = os.Remove(filePath); err == nil { diff --git a/plugins/input/jmxfetch/manager_test.go b/plugins/input/jmxfetch/manager_test.go index 646cd816ea..dbbf6dfa69 100644 --- a/plugins/input/jmxfetch/manager_test.go +++ b/plugins/input/jmxfetch/manager_test.go @@ -15,7 +15,7 @@ package jmxfetch import ( - "io/ioutil" + "os" "testing" "time" @@ -84,7 +84,7 @@ func TestManager_Register_static_config(t *testing.T) { }, }, false) time.Sleep(time.Second * 8) - bytes, err := ioutil.ReadFile(m.jmxfetchConfPath + "/test1.yaml") + bytes, err := os.ReadFile(m.jmxfetchConfPath + "/test1.yaml") assert.NoErrorf(t, err, "file not read") assert.Equal(t, string(bytes), expectCfg) } diff --git a/plugins/input/mockd/input_mockd.go b/plugins/input/mockd/input_mockd.go index a4b67e80a3..d59a5024e6 100644 --- a/plugins/input/mockd/input_mockd.go +++ b/plugins/input/mockd/input_mockd.go @@ -15,7 +15,7 @@ package mockd import ( - "io/ioutil" + "os" "strconv" "sync" "time" @@ -40,7 +40,7 @@ type ServiceMock struct { func (p *ServiceMock) Init(context pipeline.Context) (int, error) { p.context = context if len(p.File) > 0 { - if content, _ := ioutil.ReadFile(p.File); len(content) > 0 { + if content, _ := os.ReadFile(p.File); len(content) > 0 { if p.Fields == nil { p.Fields = make(map[string]string) } diff --git a/plugins/input/mysql/mysql.go b/plugins/input/mysql/mysql.go index ea8157ec53..09429c15c4 100644 --- a/plugins/input/mysql/mysql.go +++ b/plugins/input/mysql/mysql.go @@ -18,7 +18,7 @@ import ( "database/sql" "encoding/json" "fmt" - "io/ioutil" + "os" "strconv" "strings" "sync" @@ -91,7 +91,7 @@ type Mysql struct { func (m *Mysql) Init(context pipeline.Context) (int, error) { m.context = context if len(m.StateMent) == 0 && len(m.StateMentPath) != 0 { - data, err := ioutil.ReadFile(m.StateMentPath) + data, err := os.ReadFile(m.StateMentPath) if err != nil && len(data) > 0 { m.StateMent = string(data) } else { diff --git a/plugins/input/netping/netping.go b/plugins/input/netping/netping.go index 3fce8ddfc0..f8d8c7f923 100644 --- a/plugins/input/netping/netping.go +++ b/plugins/input/netping/netping.go @@ -18,7 +18,7 @@ import ( "context" "crypto/rand" "fmt" - "io/ioutil" + "io" "math" "math/big" "net" @@ -610,7 +610,7 @@ func (m *NetPing) doHTTPing(config *HTTPConfig) { successCount := 1 defer resp.Body.Close() - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { m.resultChannel <- &Result{ Valid: true, diff --git a/plugins/input/prometheus/input_prometheus.go b/plugins/input/prometheus/input_prometheus.go index f3a590ecf8..3a05ffeaea 100644 --- a/plugins/input/prometheus/input_prometheus.go +++ b/plugins/input/prometheus/input_prometheus.go @@ -18,7 +18,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "strconv" @@ -95,7 +95,7 @@ func (p *ServiceStaticPrometheus) Init(context pipeline.Context) (int, error) { defer func(f *os.File) { _ = f.Close() }(f) - bytes, err := ioutil.ReadAll(f) + bytes, err := io.ReadAll(f) if err != nil { return 0, fmt.Errorf("cannot read prometheus configuration file") } diff --git a/plugins/input/rdb/rdb.go b/plugins/input/rdb/rdb.go index a4bc6f26ca..a4ef4832dc 100644 --- a/plugins/input/rdb/rdb.go +++ b/plugins/input/rdb/rdb.go @@ -18,7 +18,7 @@ import ( "database/sql" "encoding/json" "fmt" - "io/ioutil" + "os" "strings" "sync" "time" @@ -87,7 +87,7 @@ func (m *Rdb) Init(context pipeline.Context, rdbFunc RdbFunc) (int, error) { initAlarmName := fmt.Sprintf("%s_INIT_ALARM", strings.ToUpper(m.Driver)) m.Context = context if len(m.StateMent) == 0 && len(m.StateMentPath) != 0 { - data, err := ioutil.ReadFile(m.StateMentPath) + data, err := os.ReadFile(m.StateMentPath) if err != nil && len(data) > 0 { m.StateMent = string(data) } else { diff --git a/plugins/input/skywalkingv3/jvm_metric_handle_test.go b/plugins/input/skywalkingv3/jvm_metric_handle_test.go index ff8a748f4f..47fbb9a923 100644 --- a/plugins/input/skywalkingv3/jvm_metric_handle_test.go +++ b/plugins/input/skywalkingv3/jvm_metric_handle_test.go @@ -19,7 +19,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "os" "path/filepath" "testing" @@ -47,7 +47,7 @@ func TestJvmMetrics(t *testing.T) { func validate(expectedResultPath string, result []*protocol.Log, t *testing.T) { jsonBytes, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(jsonBytes)) - expected, _ := ioutil.ReadFile(filepath.Clean(expectedResultPath)) + expected, _ := os.ReadFile(filepath.Clean(expectedResultPath)) temp := make([]*protocol.Log, 0, 16) json.Unmarshal(expected, &temp) expected, _ = json.MarshalIndent(temp, "", " ") diff --git a/plugins/input/systemv2/input_system_linux.go b/plugins/input/systemv2/input_system_linux.go index 78da22e1de..4f148b4f0f 100644 --- a/plugins/input/systemv2/input_system_linux.go +++ b/plugins/input/systemv2/input_system_linux.go @@ -20,7 +20,7 @@ package systemv2 import ( "bufio" "bytes" - "io/ioutil" + "io" "os" "strconv" "strings" @@ -152,7 +152,7 @@ func (r *InputSystem) CollectOpenFD(collector pipeline.Collector) { defer func(file *os.File) { _ = file.Close() }(file) - content, err := ioutil.ReadAll(file) + content, err := io.ReadAll(file) if err != nil { logger.Error(r.context.GetRuntimeContext(), "READ_FILENR_ALARM", "err", err) return diff --git a/plugins/input/telegraf/telegraf_manager.go b/plugins/input/telegraf/telegraf_manager.go index 0251464c00..4343ed7633 100644 --- a/plugins/input/telegraf/telegraf_manager.go +++ b/plugins/input/telegraf/telegraf_manager.go @@ -17,7 +17,6 @@ package telegraf import ( "context" "fmt" - "io/ioutil" "os" "os/exec" "path" @@ -142,7 +141,7 @@ func (tm *Manager) initAgentDir() { } } else { // Clean config files (outdated) in conf directory. - if files, err := ioutil.ReadDir(tm.telegrafConfPath); err == nil { + if files, err := os.ReadDir(tm.telegrafConfPath); err == nil { for _, f := range files { filePath := path.Join(tm.telegrafConfPath, f.Name()) if err = os.Remove(filePath); err == nil { @@ -158,7 +157,7 @@ func (tm *Manager) initAgentDir() { } } defaultConfigPath := path.Join(tm.telegrafPath, defaultConfFileName) - if err := ioutil.WriteFile(defaultConfigPath, []byte(fmt.Sprintf(defaultConfig, logger.DebugFlag())), 0600); err != nil { + if err := os.WriteFile(defaultConfigPath, []byte(fmt.Sprintf(defaultConfig, logger.DebugFlag())), 0600); err != nil { logger.Warningf(telegrafManager.GetContext(), "SERVICE_TELEGRAF_RUNTIME_ALARM", "write default config error, path: %v, err: %v", defaultConfigPath, err) } @@ -262,7 +261,7 @@ func (tm *Manager) overwriteConfigFile(cfg *Config) bool { "overwrite local config file error, path: %v err: %v", filePath, err) return false } - if err := ioutil.WriteFile(filePath, []byte(cfg.Detail), 0600); err != nil { + if err := os.WriteFile(filePath, []byte(cfg.Detail), 0600); err != nil { logger.Warningf(telegrafManager.GetContext(), "SERVICE_TELEGRAF_OVERWRITE_CONFIG_ALARM", "overwrite local config file error, path: %v err: %v", filePath, err) return false diff --git a/plugins/input/telegraf/telegraf_manager_test.go b/plugins/input/telegraf/telegraf_manager_test.go index 77191d5c7e..03780a4040 100644 --- a/plugins/input/telegraf/telegraf_manager_test.go +++ b/plugins/input/telegraf/telegraf_manager_test.go @@ -17,7 +17,6 @@ package telegraf import ( "context" "fmt" - "io/ioutil" "os" "os/exec" "path" @@ -44,7 +43,7 @@ func (tm *Manager) isRunning() bool { } func init() { - data, err := ioutil.ReadFile("local_test/telegraf_test.conf") + data, err := os.ReadFile("local_test/telegraf_test.conf") if err != nil { panic(err) } @@ -85,15 +84,15 @@ func TestDeleteOutdatedConfig(t *testing.T) { confPath := path.Join(testTelegrafPath, "conf.d") require.NoError(t, os.MkdirAll(confPath, 0750)) - require.NoError(t, ioutil.WriteFile(path.Join(confPath, "a.conf"), []byte(`content`), 0600)) - require.NoError(t, ioutil.WriteFile(path.Join(confPath, "b.conf"), []byte(`content`), 0600)) - files, err := ioutil.ReadDir(confPath) + require.NoError(t, os.WriteFile(path.Join(confPath, "a.conf"), []byte(`content`), 0600)) + require.NoError(t, os.WriteFile(path.Join(confPath, "b.conf"), []byte(`content`), 0600)) + files, err := os.ReadDir(confPath) require.NoError(t, err) require.Equal(t, len(files), 2) getTestTelegrafManager(t) - files, err = ioutil.ReadDir(confPath) + files, err = os.ReadDir(confPath) require.NoError(t, err) require.Equal(t, len(files), 0) } @@ -239,7 +238,7 @@ func TestInstall(t *testing.T) { require.False(t, inst.install()) fileContent := fmt.Sprintf("#!/bin/sh\nmv %v %v", tmpName, inst.telegrafdPath) - require.NoError(t, ioutil.WriteFile(scriptPath, []byte(fileContent), 0600)) + require.NoError(t, os.WriteFile(scriptPath, []byte(fileContent), 0600)) require.True(t, inst.install()) require.True(t, isPathExists(inst.telegrafdPath)) diff --git a/plugins/processor/encrypt/processor_encrypt.go b/plugins/processor/encrypt/processor_encrypt.go index e0fdfe2cb5..76142c7808 100644 --- a/plugins/processor/encrypt/processor_encrypt.go +++ b/plugins/processor/encrypt/processor_encrypt.go @@ -24,7 +24,7 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" + "os" "strings" "github.com/alibaba/ilogtail/pkg/helper" @@ -167,7 +167,7 @@ func (p *ProcessorEncrypt) parseKey() error { if len(p.EncryptionParameters.KeyFilePath) > 0 { // Key is stored in local file in JSON format, load from file. var fileBytes []byte - if fileBytes, err = ioutil.ReadFile(p.EncryptionParameters.KeyFilePath); err == nil { + if fileBytes, err = os.ReadFile(p.EncryptionParameters.KeyFilePath); err == nil { err = json.Unmarshal(fileBytes, p.EncryptionParameters) } if err != nil { diff --git a/plugins/processor/encrypt/processor_encrypt_test.go b/plugins/processor/encrypt/processor_encrypt_test.go index d0d8639039..b180b6e860 100644 --- a/plugins/processor/encrypt/processor_encrypt_test.go +++ b/plugins/processor/encrypt/processor_encrypt_test.go @@ -19,7 +19,7 @@ import ( "encoding/hex" "encoding/json" "io" - "io/ioutil" + "os" "os/exec" "testing" @@ -90,11 +90,11 @@ func testProcess(t *testing.T, p *ProcessorEncrypt) { outputFilePath := "/tmp/test_aes_output" ciphertextBytes, err := hex.DecodeString(ciphertext) require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(inputFilePath, ciphertextBytes, 0600|0755)) + require.NoError(t, os.WriteFile(inputFilePath, ciphertextBytes, 0600|0755)) require.NoError(t, exec.Command("openssl", "enc", "-d", "-aes-256-cbc", "-iv", iv, //nolint:gosec "-K", p.EncryptionParameters.Key, "-in", inputFilePath, "-out", outputFilePath).Run()) - plaintext, err := ioutil.ReadFile(outputFilePath) + plaintext, err := os.ReadFile(outputFilePath) require.NoError(t, err) require.Equal(t, text, string(plaintext)) } @@ -114,7 +114,7 @@ func TestKeyFile(t *testing.T) { fileBytes, err := json.Marshal(struct{ Key string }{hex.EncodeToString(getRandomBytes(32))}) require.NoError(t, err) keyFilePath := "/tmp/test_aes_key.json" - require.NoError(t, ioutil.WriteFile(keyFilePath, fileBytes, 0600|0755)) + require.NoError(t, os.WriteFile(keyFilePath, fileBytes, 0600|0755)) p := newProcessor(nil, []byte("file://"+keyFilePath), nil, keyFilePath) testProcess(t, p) diff --git a/plugins/test/common.go b/plugins/test/common.go index 2bbfa74f1f..6c015642f6 100644 --- a/plugins/test/common.go +++ b/plugins/test/common.go @@ -16,8 +16,8 @@ package test import ( "context" - "io/ioutil" "net" + "os" "os/exec" "path/filepath" "runtime" @@ -41,7 +41,7 @@ import ( func GetTestConfig(configName string) string { fileName := "./" + configName + ".json" - byteStr, err := ioutil.ReadFile(filepath.Clean(fileName)) + byteStr, err := os.ReadFile(filepath.Clean(fileName)) if err != nil { logger.Warning(context.Background(), "read", fileName, "error", err) } diff --git a/test/case/behavior/input_observer_http/mock/main.go b/test/case/behavior/input_observer_http/mock/main.go index 804a3c28c4..3248d0df0f 100644 --- a/test/case/behavior/input_observer_http/mock/main.go +++ b/test/case/behavior/input_observer_http/mock/main.go @@ -18,7 +18,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "math/rand" "net/http" "strconv" @@ -106,7 +105,7 @@ func mockHttpClient() { if err == nil { atomic.AddInt64(&SuccessCount, 1) atomic.AddInt64(&TotalLatency, afterTime.Sub(beforeTime).Microseconds()) - io.Copy(ioutil.Discard, resp.Body) + io.Copy(io.Discard, resp.Body) resp.Body.Close() if *print { fmt.Printf("request : %s, response : %d \n", request.URL.Path, resp.StatusCode) diff --git a/tools/builder/main.go b/tools/builder/main.go index b3dd9650ef..8948891a8b 100644 --- a/tools/builder/main.go +++ b/tools/builder/main.go @@ -18,7 +18,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "net/http" "os" "os/exec" @@ -42,7 +42,7 @@ var gitExe = flag.String("git-exe", "git", "the git executable binary path") func main() { flag.Parse() - goModContent, err := ioutil.ReadFile(filepath.Join(*projectRoot, "go.mod")) + goModContent, err := os.ReadFile(filepath.Join(*projectRoot, "go.mod")) if err != nil { fmt.Println("failed to read go.mod in project root:", *projectRoot) os.Exit(1) @@ -116,13 +116,13 @@ func loadPluginConfig(file string) (*pluginConfig, error) { return nil, err } defer resp.Body.Close() - content, err = ioutil.ReadAll(resp.Body) + content, err = io.ReadAll(resp.Body) if err != nil { return nil, err } } else { var err error - content, err = ioutil.ReadFile(file) // nolint + content, err = os.ReadFile(file) // nolint if err != nil { return nil, err } @@ -255,7 +255,7 @@ func getGoModules(ctx *buildContext) error { return fmt.Errorf("failed to download go modules, err: %w, output: %s", err, out) } - mods, err := ioutil.ReadFile(ctx.ModFile) + mods, err := os.ReadFile(ctx.ModFile) if err != nil { return fmt.Errorf("failed to read file content, err: %v", err) } diff --git a/tools/builder/main_test.go b/tools/builder/main_test.go index 441b885ed4..d9ad9ec586 100644 --- a/tools/builder/main_test.go +++ b/tools/builder/main_test.go @@ -15,8 +15,8 @@ package main import ( - "io/ioutil" "net/http" + "os" "path/filepath" "testing" @@ -29,7 +29,7 @@ func Test_loadPluginConfig(t *testing.T) { defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("GET", "https://test.com/external_plugins_config", func(req *http.Request) (*http.Response, error) { - data, err := ioutil.ReadFile("testdata/external_plugins.yml") + data, err := os.ReadFile("testdata/external_plugins.yml") assert.Nil(t, err) return httpmock.NewBytesResponse(200, data), nil }) @@ -251,7 +251,7 @@ replace github.com/mock/common_plugins1 v1.0.0 => ../ assert.Nil(t, err) for path, expect := range wants { - actual, err := ioutil.ReadFile(filepath.Join(ctx.ProjectRoot, path)) + actual, err := os.ReadFile(filepath.Join(ctx.ProjectRoot, path)) assert.Nil(t, err) assert.Equal(t, expect, string(actual)) }