From 9c7b2b80e093425d6704f23032bf4c0030ca0c42 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Thu, 13 Jul 2023 17:21:35 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil --- exporter/http_test.go | 4 ++-- exporter/pwd_file.go | 4 ++-- exporter/tls.go | 4 ++-- main.go | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/exporter/http_test.go b/exporter/http_test.go index 6395f09a..4ed87d89 100644 --- a/exporter/http_test.go +++ b/exporter/http_test.go @@ -2,7 +2,7 @@ package exporter import ( "fmt" - "io/ioutil" + "io" "math/rand" "net" "net/http" @@ -373,7 +373,7 @@ func downloadURLWithStatusCode(t *testing.T, u string) (int, string) { t.Fatal(err) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) } diff --git a/exporter/pwd_file.go b/exporter/pwd_file.go index 1abfaa83..dfeaf54f 100644 --- a/exporter/pwd_file.go +++ b/exporter/pwd_file.go @@ -2,7 +2,7 @@ package exporter import ( "encoding/json" - "io/ioutil" + "os" log "github.com/sirupsen/logrus" ) @@ -12,7 +12,7 @@ func LoadPwdFile(passwordFile string) (map[string]string, error) { res := make(map[string]string) log.Debugf("start load password file: %s", passwordFile) - bytes, err := ioutil.ReadFile(passwordFile) + bytes, err := os.ReadFile(passwordFile) if err != nil { log.Warnf("load password file failed: %s", err) return nil, err diff --git a/exporter/tls.go b/exporter/tls.go index fbc28c35..f5e3c853 100644 --- a/exporter/tls.go +++ b/exporter/tls.go @@ -4,7 +4,7 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" + "os" log "github.com/sirupsen/logrus" ) @@ -111,7 +111,7 @@ func LoadKeyPair(certFile, keyFile string) (*tls.Certificate, error) { // The file must contain PEM encoded data. func LoadCAFile(caFile string) (*x509.CertPool, error) { log.Debugf("Load CA cert file: %s", caFile) - pemCerts, err := ioutil.ReadFile(caFile) + pemCerts, err := os.ReadFile(caFile) if err != nil { return nil, err } diff --git a/main.go b/main.go index a4a1d711..6ab8424c 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "io/ioutil" "net/http" "os" "runtime" @@ -140,7 +139,7 @@ func main() { scripts := strings.Split(*scriptPath, ",") ls = make(map[string][]byte, len(scripts)) for _, script := range scripts { - if ls[script], err = ioutil.ReadFile(script); err != nil { + if ls[script], err = os.ReadFile(script); err != nil { log.Fatalf("Error loading script file %s err: %s", script, err) } }