From cc82d49a73be9a108b4ffe682f4cf3be18a408c4 Mon Sep 17 00:00:00 2001 From: Abhinav Nair <11939846+abhinavnair@users.noreply.github.com> Date: Sun, 26 Jun 2022 16:37:23 +0800 Subject: [PATCH] Replace deprecated ioutil pkg with os & io As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. So replacing all usage of ioutil pkg with io & os. --- cmd/mockery.go | 7 +++---- pkg/generator_test.go | 6 +++--- pkg/parse.go | 4 ++-- pkg/walker.go | 3 +-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/mockery.go b/cmd/mockery.go index 7aa4b3ca..ecf1cc9b 100644 --- a/cmd/mockery.go +++ b/cmd/mockery.go @@ -3,7 +3,6 @@ package cmd import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -11,7 +10,7 @@ import ( "strings" "time" - homedir "github.com/mitchellh/go-homedir" + "github.com/mitchellh/go-homedir" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -99,7 +98,7 @@ func printStackTrace(e error) { // Execute executes the cobra CLI workflow func Execute() { if err := NewRootCmd().Execute(); err != nil { - //printStackTrace(err) + // printStackTrace(err) os.Exit(1) } } @@ -247,7 +246,7 @@ func (r *RootApp) Run() error { var boilerplate string if r.Config.BoilerplateFile != "" { - data, err := ioutil.ReadFile(r.Config.BoilerplateFile) + data, err := os.ReadFile(r.Config.BoilerplateFile) if err != nil { log.Fatal().Msgf("Failed to read boilerplate file %s: %v", r.Config.BoilerplateFile, err) } diff --git a/pkg/generator_test.go b/pkg/generator_test.go index 98313d1c..b1cab16c 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -5,7 +5,7 @@ import ( "context" "go/format" "io" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -1359,7 +1359,7 @@ func NewRequesterReturnElided(t mockConstructorTestingTNewRequesterReturnElided) } func (s *GeneratorSuite) TestGeneratorVariadicArgs() { - expectedBytes, err := ioutil.ReadFile(getMocksPath("RequesterVariadic.go")) + expectedBytes, err := os.ReadFile(getMocksPath("RequesterVariadic.go")) s.NoError(err) expected := string(expectedBytes) expected = expected[strings.Index(expected, "// RequesterVariadic is"):] @@ -1367,7 +1367,7 @@ func (s *GeneratorSuite) TestGeneratorVariadicArgs() { } func (s *GeneratorSuite) TestGeneratorVariadicArgsAsOneArg() { - expectedBytes, err := ioutil.ReadFile(getMocksPath("RequesterVariadicOneArgument.go")) + expectedBytes, err := os.ReadFile(getMocksPath("RequesterVariadicOneArgument.go")) s.NoError(err) expected := string(expectedBytes) expected = expected[strings.Index(expected, "// RequesterVariadicOneArgument is"):] diff --git a/pkg/parse.go b/pkg/parse.go index ba42a297..8cf0c0c1 100644 --- a/pkg/parse.go +++ b/pkg/parse.go @@ -5,7 +5,7 @@ import ( "fmt" "go/ast" "go/types" - "io/ioutil" + "os" "path/filepath" "sort" "strings" @@ -73,7 +73,7 @@ func (p *Parser) Parse(ctx context.Context, path string) error { dir := filepath.Dir(path) - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return err } diff --git a/pkg/walker.go b/pkg/walker.go index a05aa662..75e338b7 100644 --- a/pkg/walker.go +++ b/pkg/walker.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -70,7 +69,7 @@ func (w *Walker) doWalk(ctx context.Context, p *Parser, dir string, visitor Walk log := zerolog.Ctx(ctx) ctx = log.WithContext(ctx) - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return }