From a9777a37792a97e765b0ce42a97a61d794510436 Mon Sep 17 00:00:00 2001 From: Ilyes512 Date: Sun, 26 Nov 2023 18:33:25 +0100 Subject: [PATCH] Replaced deprecated io/ioutil package --- pkg/boilr/configuration.go | 3 +-- pkg/cmd/use.go | 3 +-- pkg/cmd/use_test.go | 5 ++--- pkg/cmd/util/validation.go | 3 +-- pkg/template/template.go | 7 +++---- pkg/util/exec/cmd.go | 6 +++--- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pkg/boilr/configuration.go b/pkg/boilr/configuration.go index e8b4930..f4f72d9 100644 --- a/pkg/boilr/configuration.go +++ b/pkg/boilr/configuration.go @@ -3,7 +3,6 @@ package boilr import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" @@ -104,7 +103,7 @@ func init() { return } - buf, err := ioutil.ReadFile(Configuration.FilePath) + buf, err := os.ReadFile(Configuration.FilePath) if err != nil { exit.Error(err) } diff --git a/pkg/cmd/use.go b/pkg/cmd/use.go index 1d1cae8..f99c401 100644 --- a/pkg/cmd/use.go +++ b/pkg/cmd/use.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -83,7 +82,7 @@ var Use = &cli.Command{ return fmt.Errorf("use: parent directory %q doesn't exist", parentDir) } - tmpDir, err := ioutil.TempDir("", "boilr-use-template") + tmpDir, err := os.MkdirTemp("", "boilr-use-template") if err != nil { return err } diff --git a/pkg/cmd/use_test.go b/pkg/cmd/use_test.go index 6a924ac..5751c15 100644 --- a/pkg/cmd/use_test.go +++ b/pkg/cmd/use_test.go @@ -1,7 +1,6 @@ package cmd_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -11,9 +10,9 @@ import ( func TestUseExecutesProjectTemplate(t *testing.T) { t.SkipNow() - tmpDirPath, err := ioutil.TempDir("", "template-test") + tmpDirPath, err := os.MkdirTemp("", "template-test") if err != nil { - t.Fatalf("ioutil.TempDir() got error -> %v", err) + t.Fatalf("os.MkdirTemp() got error -> %v", err) } // else { // defer os.RemoveAll(tmpDirPath) diff --git a/pkg/cmd/util/validation.go b/pkg/cmd/util/validation.go index 0c636f2..74d127f 100644 --- a/pkg/cmd/util/validation.go +++ b/pkg/cmd/util/validation.go @@ -3,7 +3,6 @@ package util import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" @@ -70,7 +69,7 @@ func ValidateArgs(args []string, validations []validate.Argument) error { } func testTemplate(path string) error { - tmpDir, err := ioutil.TempDir("", "boilr-validation-test") + tmpDir, err := os.MkdirTemp("", "boilr-validation-test") if err != nil { return err } diff --git a/pkg/template/template.go b/pkg/template/template.go index 050ede9..a829400 100644 --- a/pkg/template/template.go +++ b/pkg/template/template.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -57,7 +56,7 @@ func Get(path string) (Interface, error) { } defer f.Close() - buf, err := ioutil.ReadAll(f) + buf, err := io.ReadAll(f) if err != nil { return nil, err } @@ -83,7 +82,7 @@ func Get(path string) (Interface, error) { return Metadata{}, nil } - b, err := ioutil.ReadFile(filepath.Join(absPath, boilr.TemplateMetadataName)) + b, err := os.ReadFile(filepath.Join(absPath, boilr.TemplateMetadataName)) if err != nil { return Metadata{}, err } @@ -217,7 +216,7 @@ func (t *dirTemplate) Execute(dirPrefix string) error { } defer func(fname string) { - contents, err := ioutil.ReadFile(fname) + contents, err := os.ReadFile(fname) if err != nil { tlog.Debug(fmt.Sprintf("couldn't read the contents of file %q, got error %q", fname, err)) return diff --git a/pkg/util/exec/cmd.go b/pkg/util/exec/cmd.go index bf03b68..5db841b 100644 --- a/pkg/util/exec/cmd.go +++ b/pkg/util/exec/cmd.go @@ -3,7 +3,7 @@ package exec import ( "errors" "fmt" - "io/ioutil" + "io" "os/exec" ) @@ -28,13 +28,13 @@ func Cmd(executable string, args ...string) (string, error) { return "", err } - outBuf, err := ioutil.ReadAll(stdout) + outBuf, err := io.ReadAll(stdout) if err != nil { return "", err } out := string(outBuf) - errBuf, err := ioutil.ReadAll(stderr) + errBuf, err := io.ReadAll(stderr) if err != nil { fmt.Println(errBuf) return "", err