mockgen: replace io/ioutil with io and os package

Signed-off-by: cui fliter <imcusg@gmail.com>
This commit is contained in:
cui fliter 2022-09-14 14:04:13 +08:00
Родитель 5b455625bd
Коммит 3a3b30bdf0
4 изменённых файлов: 11 добавлений и 14 удалений

Просмотреть файл

@ -26,7 +26,6 @@ import (
"fmt"
"go/token"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@ -149,7 +148,7 @@ func main() {
g.mockNames = parseMockNames(*mockNames)
}
if *copyrightFile != "" {
header, err := ioutil.ReadFile(*copyrightFile)
header, err := os.ReadFile(*copyrightFile)
if err != nil {
log.Fatalf("Failed reading copyright file: %v", err)
}
@ -165,7 +164,7 @@ func main() {
if err := os.MkdirAll(filepath.Dir(*destination), os.ModePerm); err != nil {
log.Fatalf("Unable to create directory: %v", err)
}
existing, err := ioutil.ReadFile(*destination)
existing, err := os.ReadFile(*destination)
if err != nil && !errors.Is(err, os.ErrNotExist) {
log.Fatalf("Failed reading pre-exiting destination file: %v", err)
}
@ -704,7 +703,7 @@ func parsePackageImport(srcDir string) (string, error) {
if moduleMode != "off" {
currentDir := srcDir
for {
dat, err := ioutil.ReadFile(filepath.Join(currentDir, "go.mod"))
dat, err := os.ReadFile(filepath.Join(currentDir, "go.mod"))
if os.IsNotExist(err) {
if currentDir == filepath.Dir(currentDir) {
// at the root

Просмотреть файл

@ -2,7 +2,6 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -369,7 +368,7 @@ func Test_createPackageMap(t *testing.T) {
}
func TestParsePackageImport_FallbackGoPath(t *testing.T) {
goPath, err := ioutil.TempDir("", "gopath")
goPath, err := os.MkdirTemp("", "gopath")
if err != nil {
t.Error(err)
}
@ -404,7 +403,7 @@ func TestParsePackageImport_FallbackMultiGoPath(t *testing.T) {
var goPathList []string
// first gopath
goPath, err := ioutil.TempDir("", "gopath1")
goPath, err := os.MkdirTemp("", "gopath1")
if err != nil {
t.Error(err)
}
@ -421,7 +420,7 @@ func TestParsePackageImport_FallbackMultiGoPath(t *testing.T) {
}
// second gopath
goPath, err = ioutil.TempDir("", "gopath2")
goPath, err = os.MkdirTemp("", "gopath2")
if err != nil {
t.Error(err)
}

Просмотреть файл

@ -26,8 +26,8 @@ import (
"go/parser"
"go/token"
"go/types"
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"strconv"
@ -701,7 +701,7 @@ func isVariadic(f *ast.FuncType) bool {
// packageNameOfDir get package import path via dir
func packageNameOfDir(srcDir string) (string, error) {
files, err := ioutil.ReadDir(srcDir)
files, err := os.ReadDir(srcDir)
if err != nil {
log.Fatal(err)
}

Просмотреть файл

@ -23,7 +23,6 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@ -92,7 +91,7 @@ func writeProgram(importPath string, symbols []string) ([]byte, error) {
// run the given program and parse the output as a model.Package.
func run(program string) (*model.Package, error) {
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
if err != nil {
return nil, err
}
@ -133,7 +132,7 @@ func run(program string) (*model.Package, error) {
// parses the output as a model.Package.
func runInDir(program []byte, dir string) (*model.Package, error) {
// We use TempDir instead of TempFile so we can control the filename.
tmpDir, err := ioutil.TempDir(dir, "gomock_reflect_")
tmpDir, err := os.MkdirTemp(dir, "gomock_reflect_")
if err != nil {
return nil, err
}
@ -149,7 +148,7 @@ func runInDir(program []byte, dir string) (*model.Package, error) {
progBinary += ".exe"
}
if err := ioutil.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil {
if err := os.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil {
return nil, err
}