Skip to content

Commit

Permalink
Replace deprecated ioutil pkg with os & io
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
abhinavnair committed Jun 26, 2022
1 parent ca9ddd4 commit cc82d49
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
7 changes: 3 additions & 4 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"runtime/pprof"
"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"
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"go/format"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -1359,15 +1359,15 @@ 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"):]
s.checkGeneration("requester_variadic.go", "RequesterVariadic", false, "", expected)
}

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"):]
Expand Down
4 changes: 2 additions & 2 deletions pkg/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"go/ast"
"go/types"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit cc82d49

Please sign in to comment.