From 5462ce00974764914ff0054df176d77e1ca3d3e0 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Wed, 19 Jul 2023 09:11:09 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil --- dirs.go | 4 ++-- main_test.go | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dirs.go b/dirs.go index 4fb9a52..7ee4c47 100644 --- a/dirs.go +++ b/dirs.go @@ -5,12 +5,12 @@ package main import ( - "io/ioutil" + "os" ) // Dirs returns a slice of all the directories within a given directory func Dirs(path string) []string { - files, err := ioutil.ReadDir(path) + files, err := os.ReadDir(path) if err != nil { return nil } diff --git a/main_test.go b/main_test.go index 4f34797..1a19228 100644 --- a/main_test.go +++ b/main_test.go @@ -7,7 +7,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -101,7 +100,7 @@ func TestGofmt(t *testing.T) { func TestGoPyErrors(t *testing.T) { pyvm := testBackends["py3"] - workdir, err := ioutil.TempDir("", "gopy-") + workdir, err := os.MkdirTemp("", "gopy-") if err != nil { t.Fatalf("could not create workdir: %v\n", err) } @@ -886,14 +885,14 @@ don't modify manually. } if os.Getenv("GOPY_GENERATE_SUPPORT_MATRIX") == "1" { - err := ioutil.WriteFile("SUPPORT_MATRIX.md", buf.Bytes(), 0644) + err := os.WriteFile("SUPPORT_MATRIX.md", buf.Bytes(), 0644) if err != nil { log.Fatalf("Unable to write SUPPORT_MATRIX.md") } return } - src, err := ioutil.ReadFile("SUPPORT_MATRIX.md") + src, err := os.ReadFile("SUPPORT_MATRIX.md") if err != nil { log.Fatalf("Unable to read SUPPORT_MATRIX.md") } @@ -952,7 +951,7 @@ require github.com/go-python/gopy v0.0.0 replace github.com/go-python/gopy => %s ` contents := fmt.Sprintf(template, pkgDir) - if err := ioutil.WriteFile(filepath.Join(tstDir, "go.mod"), []byte(contents), 0666); err != nil { + if err := os.WriteFile(filepath.Join(tstDir, "go.mod"), []byte(contents), 0666); err != nil { t.Fatalf("failed to write go.mod file: %v", err) } } @@ -961,7 +960,7 @@ func testPkgBackend(t *testing.T, pyvm string, table pkg) { curPkgPath := reflect.TypeOf(table).PkgPath() _, pkgNm := filepath.Split(table.path) cwd, _ := os.Getwd() - workdir, err := ioutil.TempDir("", "gopy-") + workdir, err := os.MkdirTemp("", "gopy-") if err != nil { t.Fatalf("[%s:%s]: could not create workdir: %v\n", pyvm, table.path, err) }