From 0dccbce9a196f1416a09d90ef975e4216f72c5ee Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Thu, 11 Jul 2024 18:08:32 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil (#95) --- basic/helpers_test.go | 6 +++--- config/config.go | 4 ++-- enhanced/helpers_test.go | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/basic/helpers_test.go b/basic/helpers_test.go index 38b290ca..cbea0671 100644 --- a/basic/helpers_test.go +++ b/basic/helpers_test.go @@ -3,7 +3,7 @@ package basic import ( "bytes" "flag" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -19,7 +19,7 @@ var ( func readTestDataMetrics(t *testing.T) []string { t.Helper() - b, err := ioutil.ReadFile(filepath.Join("testdata", "all.txt")) //nolint:gosec + b, err := os.ReadFile(filepath.Join("testdata", "all.txt")) //nolint:gosec require.NoError(t, err) return strings.Split(string(bytes.TrimSpace(b)), "\n") } @@ -28,6 +28,6 @@ func writeTestDataMetrics(t *testing.T, metrics []string) { t.Helper() b := []byte(strings.TrimSpace(strings.Join(metrics, "\n")) + "\n") - err := ioutil.WriteFile(filepath.Join("testdata", "all.txt"), b, 0666) + err := os.WriteFile(filepath.Join("testdata", "all.txt"), b, 0666) require.NoError(t, err) } diff --git a/config/config.go b/config/config.go index 538732a7..03d0d815 100644 --- a/config/config.go +++ b/config/config.go @@ -1,7 +1,7 @@ package config import ( - "io/ioutil" + "os" "gopkg.in/yaml.v2" ) @@ -46,7 +46,7 @@ type Config struct { // Load loads configuration from file. func Load(filename string) (*Config, error) { - b, err := ioutil.ReadFile(filename) //nolint:gosec + b, err := os.ReadFile(filename) //nolint:gosec if err != nil { return nil, err } diff --git a/enhanced/helpers_test.go b/enhanced/helpers_test.go index 19a1d839..d47fbd13 100644 --- a/enhanced/helpers_test.go +++ b/enhanced/helpers_test.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "flag" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -20,7 +20,7 @@ var ( func readTestDataJSON(t *testing.T, instance string) []byte { t.Helper() - b, err := ioutil.ReadFile(filepath.Join("testdata", instance+".json")) //nolint:gosec + b, err := os.ReadFile(filepath.Join("testdata", instance+".json")) //nolint:gosec require.NoError(t, err) return bytes.TrimSpace(b) } @@ -33,14 +33,14 @@ func writeTestDataJSON(t *testing.T, instance string, b []byte) { require.NoError(t, err) err = buf.WriteByte('\n') require.NoError(t, err) - err = ioutil.WriteFile(filepath.Join("testdata", instance+".json"), buf.Bytes(), 0666) + err = os.WriteFile(filepath.Join("testdata", instance+".json"), buf.Bytes(), 0666) require.NoError(t, err) } func readTestDataMetrics(t *testing.T, instance string) []string { t.Helper() - b, err := ioutil.ReadFile(filepath.Join("testdata", instance+".txt")) //nolint:gosec + b, err := os.ReadFile(filepath.Join("testdata", instance+".txt")) //nolint:gosec require.NoError(t, err) return strings.Split(string(bytes.TrimSpace(b)), "\n") } @@ -49,6 +49,6 @@ func writeTestDataMetrics(t *testing.T, instance string, metrics []string) { t.Helper() b := []byte(strings.TrimSpace(strings.Join(metrics, "\n")) + "\n") - err := ioutil.WriteFile(filepath.Join("testdata", instance+".txt"), b, 0666) + err := os.WriteFile(filepath.Join("testdata", instance+".txt"), b, 0666) require.NoError(t, err) }