From 0799cd2b88946281a73656e98e26628ba902543c Mon Sep 17 00:00:00 2001 From: Taichi Sasaki Date: Wed, 30 Aug 2023 00:04:31 +0900 Subject: [PATCH] Not use deprecated io/ioutil --- providers/fs/fs.go | 4 ++-- providers/s3/s3.go | 4 ++-- tests/koanf_test.go | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/providers/fs/fs.go b/providers/fs/fs.go index c008b427..0df2de04 100644 --- a/providers/fs/fs.go +++ b/providers/fs/fs.go @@ -9,8 +9,8 @@ package fs import ( "errors" + "io" "io/fs" - "io/ioutil" ) // FS implements an fs.FS provider. @@ -32,7 +32,7 @@ func (f *FS) ReadBytes() ([]byte, error) { } defer fd.Close() - return ioutil.ReadAll(fd) + return io.ReadAll(fd) } // Read is not supported by the fs.FS provider. diff --git a/providers/s3/s3.go b/providers/s3/s3.go index 13e63436..4c7c7e2f 100644 --- a/providers/s3/s3.go +++ b/providers/s3/s3.go @@ -4,7 +4,7 @@ package s3 import ( "errors" - "io/ioutil" + "io" "github.com/rhnvrm/simples3" ) @@ -56,7 +56,7 @@ func (r *S3) ReadBytes() ([]byte, error) { defer resp.Close() - data, err := ioutil.ReadAll(resp) + data, err := io.ReadAll(resp) if err != nil { return nil, err } diff --git a/tests/koanf_test.go b/tests/koanf_test.go index bd2bd509..4f87ea58 100644 --- a/tests/koanf_test.go +++ b/tests/koanf_test.go @@ -5,7 +5,6 @@ import ( "errors" "flag" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -438,9 +437,9 @@ func TestWatchFile(t *testing.T) { ) // Create a tmp config file. - tmpDir, _ := ioutil.TempDir("", "koanf_*") // TODO: replace with t.TempDir() as of go v1.15 + tmpDir, _ := os.MkdirTemp("", "koanf_*") // TODO: replace with t.TempDir() as of go v1.15 tmpFile := filepath.Join(tmpDir, "koanf_mock") - err := ioutil.WriteFile(tmpFile, []byte(`{"parent": {"name": "name1"}}`), 0600) // TODO: replace with os.WriteFile as of go v1.16 + err := os.WriteFile(tmpFile, []byte(`{"parent": {"name": "name1"}}`), 0600) require.NoError(t, err, "error creating temp config file: %v", err) // Load the new config and watch it for changes. @@ -469,7 +468,7 @@ func TestWatchFile(t *testing.T) { // Wait a second and change the file. time.Sleep(1 * time.Second) - ioutil.WriteFile(tmpFile, []byte(`{"parent": {"name": "name2"}}`), 0600) // TODO: replace with os.WriteFile as of go v1.16 + os.WriteFile(tmpFile, []byte(`{"parent": {"name": "name2"}}`), 0600) wg.Wait() assert.Condition(func() bool { @@ -482,7 +481,7 @@ func TestWatchFileSymlink(t *testing.T) { assert = assert.New(t) k = koanf.New(delim) ) - tmpDir, _ := ioutil.TempDir("", "koanf_*") // TODO: replace with t.TempDir() as of go v1.15 + tmpDir, _ := os.MkdirTemp("", "koanf_*") // TODO: replace with t.TempDir() as of go v1.15 // Create a symlink. symPath := filepath.Join(tmpDir, "koanf_test_symlink")