io/ioutil deprecated (#3217)
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -145,9 +145,20 @@ func GetTemplateDir(category string) (string, error) {
|
||||
// backward compatible, it will be removed in the feature
|
||||
// backward compatible start.
|
||||
beforeTemplateDir := filepath.Join(home, version.GetGoctlVersion(), category)
|
||||
fs, _ := ioutil.ReadDir(beforeTemplateDir)
|
||||
entries, err := os.ReadDir(beforeTemplateDir)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
infos := make([]fs.FileInfo, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
info, err := entry.Info()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
infos = append(infos, info)
|
||||
}
|
||||
var hasContent bool
|
||||
for _, e := range fs {
|
||||
for _, e := range infos {
|
||||
if e.Size() > 0 {
|
||||
hasContent = true
|
||||
}
|
||||
@@ -256,7 +267,7 @@ func createTemplate(file, content string, force bool) error {
|
||||
|
||||
// MustTempDir creates a temporary directory.
|
||||
func MustTempDir() string {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package pathx
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -23,7 +22,7 @@ func TestGetTemplateDir(t *testing.T) {
|
||||
return
|
||||
}
|
||||
tempFile := filepath.Join(dir, "bar.txt")
|
||||
err = ioutil.WriteFile(tempFile, []byte("foo"), os.ModePerm)
|
||||
err = os.WriteFile(tempFile, []byte("foo"), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -79,7 +78,7 @@ func TestGetGoctlHome(t *testing.T) {
|
||||
t.Run("goctl_is_file", func(t *testing.T) {
|
||||
tmpFile := filepath.Join(t.TempDir(), "a.tmp")
|
||||
backupTempFile := tmpFile + ".old"
|
||||
err := ioutil.WriteFile(tmpFile, nil, 0o666)
|
||||
err := os.WriteFile(tmpFile, nil, 0o666)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package pathx
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -10,9 +9,9 @@ import (
|
||||
)
|
||||
|
||||
func TestReadLink(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "go-zero")
|
||||
dir, err := os.CreateTemp("", "go-zero")
|
||||
assert.Nil(t, err)
|
||||
symLink := filepath.Join(dir, "test")
|
||||
symLink := filepath.Join(dir.Name(), "test")
|
||||
pwd, err := os.Getwd()
|
||||
assertError(err, t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user