From 627ebc4ca75ab0316beada9e54bb6a3275f8ef42 Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Thu, 22 Dec 2022 13:40:00 +0800 Subject: [PATCH] cleanup: remove ioutil Signed-off-by: xin.li --- config_dbtester.go | 6 +++--- pkg/fileinspect/fileinspect_test.go | 3 +-- pkg/remotestorage/example/main.go | 6 +++--- pkg/remotestorage/uploader.go | 10 +++++----- util.go | 3 +-- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/config_dbtester.go b/config_dbtester.go index e48fe36a..b208d7f1 100644 --- a/config_dbtester.go +++ b/config_dbtester.go @@ -16,7 +16,7 @@ package dbtester import ( "fmt" - "io/ioutil" + "os" "path/filepath" "strings" @@ -57,7 +57,7 @@ type Config struct { // ReadConfig reads control configuration file. func ReadConfig(fpath string, analyze bool) (*Config, error) { - bts, err := ioutil.ReadFile(fpath) + bts, err := os.ReadFile(fpath) if err != nil { return nil, err } @@ -279,7 +279,7 @@ func ReadConfig(fpath string, analyze bool) (*Config, error) { } if cfg.ConfigClientMachineInitial.GoogleCloudStorageKeyPath != "" && !analyze { - bts, err = ioutil.ReadFile(cfg.ConfigClientMachineInitial.GoogleCloudStorageKeyPath) + bts, err = os.ReadFile(cfg.ConfigClientMachineInitial.GoogleCloudStorageKeyPath) if err != nil { return nil, err } diff --git a/pkg/fileinspect/fileinspect_test.go b/pkg/fileinspect/fileinspect_test.go index 511c801a..6f4e762c 100644 --- a/pkg/fileinspect/fileinspect_test.go +++ b/pkg/fileinspect/fileinspect_test.go @@ -17,7 +17,6 @@ package fileinspect import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -45,7 +44,7 @@ func writeData(fpath string, data []byte) (n int, err error) { } func createData() (dir string, n int64, err error) { - dir, err = ioutil.TempDir(os.TempDir(), "fileinspect-write-test") + dir, err = os.MkdirTemp(os.TempDir(), "fileinspect-write-test") if err != nil { return } diff --git a/pkg/remotestorage/example/main.go b/pkg/remotestorage/example/main.go index 153fe03a..8cbc16c3 100644 --- a/pkg/remotestorage/example/main.go +++ b/pkg/remotestorage/example/main.go @@ -15,8 +15,8 @@ package main import ( - "io/ioutil" "log" + "os" "github.com/etcd-io/dbtester/pkg/remotestorage" @@ -24,7 +24,7 @@ import ( ) func main() { - kbs, err := ioutil.ReadFile("key.json") + kbs, err := os.ReadFile("key.json") if err != nil { log.Fatal(err) } @@ -37,7 +37,7 @@ func main() { } // upload directories - // kbs, err := ioutil.ReadFile("key.json") + // kbs, err := os.ReadFile("key.json") // if err != nil { // log.Fatal(err) // } diff --git a/pkg/remotestorage/uploader.go b/pkg/remotestorage/uploader.go index 51111926..4506aac3 100644 --- a/pkg/remotestorage/uploader.go +++ b/pkg/remotestorage/uploader.go @@ -17,7 +17,7 @@ package remotestorage import ( "context" "fmt" - "io/ioutil" + "os" "path/filepath" "strings" @@ -91,9 +91,9 @@ func (g *GoogleCloudStorage) UploadFile(bucket, src, dst string, opts ...OpOptio } g.lg.Info("uploading", zap.String("source", src), zap.String("destination", dst)) - bts, err := ioutil.ReadFile(src) + bts, err := os.ReadFile(src) if err != nil { - return fmt.Errorf("ioutil.ReadFile(%s) %v", src, err) + return fmt.Errorf("os.ReadFile(%s) %v", src, err) } if _, err := wc.Write(bts); err != nil { return err @@ -144,9 +144,9 @@ func (g *GoogleCloudStorage) UploadDir(bucket, src, dst string, opts ...OpOption if ret.ContentType != "" { wc.ContentType = ret.ContentType } - bts, err := ioutil.ReadFile(fpath) + bts, err := os.ReadFile(fpath) if err != nil { - errc <- fmt.Errorf("ioutil.ReadFile(%s) %v", fpath, err) + errc <- fmt.Errorf("os.ReadFile(%s) %v", fpath, err) return } if _, err := wc.Write(bts); err != nil { diff --git a/util.go b/util.go index f012dbe0..59b2f52c 100644 --- a/util.go +++ b/util.go @@ -17,7 +17,6 @@ package dbtester import ( "fmt" "io" - "io/ioutil" mrand "math/rand" "net/http" "os" @@ -90,7 +89,7 @@ func exist(fpath string) bool { // and closes it. This prevents TCP/TLS connections from closing, // therefore available for reuse. func gracefulClose(resp *http.Response) { - io.Copy(ioutil.Discard, resp.Body) + io.Copy(io.Discard, resp.Body) resp.Body.Close() }