mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 00:50:20 +08:00
io/ioutil deprecated (#3217)
This commit is contained in:
parent
4f13fe8188
commit
63368d8b0c
@ -2,7 +2,6 @@ package dartgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -83,7 +82,7 @@ func genVars(dir string, isLegacy bool, scheme string, hostname string) error {
|
||||
}
|
||||
|
||||
if !fileExists(dir + "vars.dart") {
|
||||
err = ioutil.WriteFile(dir+"vars.dart", []byte(fmt.Sprintf(`const serverHost='%s://%s';`, scheme, hostname)), 0o644)
|
||||
err = os.WriteFile(dir+"vars.dart", []byte(fmt.Sprintf(`const serverHost='%s://%s';`, scheme, hostname)), 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -94,7 +93,7 @@ func genVars(dir string, isLegacy bool, scheme string, hostname string) error {
|
||||
if isLegacy {
|
||||
tpl = varTemplate
|
||||
}
|
||||
err = ioutil.WriteFile(dir+"kv.dart", []byte(tpl), 0o644)
|
||||
err = os.WriteFile(dir+"kv.dart", []byte(tpl), 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package format
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
@ -71,11 +70,11 @@ func Test_apiFormatReader_issue1721(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
importedFilename := path.Join(dir, "foo.api")
|
||||
err = ioutil.WriteFile(importedFilename, []byte{}, fs.ModePerm)
|
||||
err = os.WriteFile(importedFilename, []byte{}, fs.ModePerm)
|
||||
require.NoError(t, err)
|
||||
|
||||
filename := path.Join(subDir, "bar.api")
|
||||
err = ioutil.WriteFile(filename, []byte(fmt.Sprintf(`import "%s"`, importedFilename)), 0o644)
|
||||
err = os.WriteFile(filename, []byte(fmt.Sprintf(`import "%s"`, importedFilename)), 0o644)
|
||||
require.NoError(t, err)
|
||||
|
||||
f, err := os.Open(filename)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -25,13 +24,13 @@ func Test_ImportCycle(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
mainPath := filepath.Join(dir, mainFilename)
|
||||
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||
err = os.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
subAPath := filepath.Join(dir, subAFilename)
|
||||
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||
err = os.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
subBPath := filepath.Join(dir, subBFilename)
|
||||
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||
err = os.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = NewParser().Parse(mainPath)
|
||||
@ -55,13 +54,13 @@ func Test_MultiImportedShouldAllowed(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
mainPath := filepath.Join(dir, mainFilename)
|
||||
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||
err = os.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
subAPath := filepath.Join(dir, subAFilename)
|
||||
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||
err = os.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
subBPath := filepath.Join(dir, subBFilename)
|
||||
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||
err = os.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = NewParser().Parse(mainPath)
|
||||
@ -84,13 +83,13 @@ func Test_RedundantDeclarationShouldNotBeAllowed(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
mainPath := filepath.Join(dir, mainFilename)
|
||||
err = ioutil.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||
err = os.WriteFile(mainPath, []byte(mainSrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
subAPath := filepath.Join(dir, subAFilename)
|
||||
err = ioutil.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||
err = os.WriteFile(subAPath, []byte(subASrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
subBPath := filepath.Join(dir, subBFilename)
|
||||
err = ioutil.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||
err = os.WriteFile(subBPath, []byte(subBSrc), 0o777)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = NewParser().Parse(mainPath)
|
||||
|
@ -2,7 +2,6 @@ package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -120,7 +119,7 @@ func TestApiParser(t *testing.T) {
|
||||
|
||||
t.Run("nestedImport", func(t *testing.T) {
|
||||
file := filepath.Join(pathx.MustTempDir(), "foo.api")
|
||||
err := ioutil.WriteFile(file, []byte(nestedAPIImport), os.ModePerm)
|
||||
err := os.WriteFile(file, []byte(nestedAPIImport), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -150,7 +149,7 @@ func TestApiParser(t *testing.T) {
|
||||
|
||||
t.Run("ambiguousSyntax", func(t *testing.T) {
|
||||
file := filepath.Join(pathx.MustTempDir(), "foo.api")
|
||||
err := ioutil.WriteFile(file, []byte(ambiguousSyntax), os.ModePerm)
|
||||
err := os.WriteFile(file, []byte(ambiguousSyntax), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -164,7 +163,7 @@ func TestApiParser(t *testing.T) {
|
||||
|
||||
t.Run("ambiguousSyntax", func(t *testing.T) {
|
||||
file := filepath.Join(pathx.MustTempDir(), "foo.api")
|
||||
err := ioutil.WriteFile(file, []byte(ambiguousSyntax), os.ModePerm)
|
||||
err := os.WriteFile(file, []byte(ambiguousSyntax), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -178,7 +177,7 @@ func TestApiParser(t *testing.T) {
|
||||
|
||||
t.Run("ambiguousService", func(t *testing.T) {
|
||||
file := filepath.Join(pathx.MustTempDir(), "foo.api")
|
||||
err := ioutil.WriteFile(file, []byte(ambiguousService), os.ModePerm)
|
||||
err := os.WriteFile(file, []byte(ambiguousService), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -208,7 +207,7 @@ func TestApiParser(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
|
||||
file := filepath.Join(pathx.MustTempDir(), "foo.api")
|
||||
err = ioutil.WriteFile(file, []byte(duplicateHandler), os.ModePerm)
|
||||
err = os.WriteFile(file, []byte(duplicateHandler), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -237,7 +236,7 @@ func TestApiParser(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
|
||||
file := filepath.Join(pathx.MustTempDir(), "foo.api")
|
||||
err = ioutil.WriteFile(file, []byte(duplicateRoute), os.ModePerm)
|
||||
err = os.WriteFile(file, []byte(duplicateRoute), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -261,7 +260,7 @@ func TestApiParser(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
|
||||
file := filepath.Join(pathx.MustTempDir(), "foo.api")
|
||||
err = ioutil.WriteFile(file, []byte(duplicateType), os.ModePerm)
|
||||
err = os.WriteFile(file, []byte(duplicateType), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
3
tools/goctl/compare/testdata/testdata.go
vendored
3
tools/goctl/compare/testdata/testdata.go
vendored
@ -2,7 +2,6 @@ package testdata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -78,7 +77,7 @@ func mustGetTestData(baseDir string) (Files, Files) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
return data, ioutil.WriteFile(fp, []byte(data.Content), os.ModePerm)
|
||||
return data, os.WriteFile(fp, []byte(data.Content), os.ModePerm)
|
||||
}
|
||||
oldDir := filepath.Join(baseDir, "old_fs")
|
||||
newDir := filepath.Join(baseDir, "new_fs")
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -163,7 +162,7 @@ func writeFile(pkgs []*ast.Package, verbose bool) error {
|
||||
return fmt.Errorf("[rewriteImport] format file %s error: %w", filename, err)
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filename, w.Bytes(), os.ModePerm)
|
||||
err = os.WriteFile(filename, w.Bytes(), os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[rewriteImport] write file %s error: %w", filename, err)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package migrate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@ -34,7 +34,7 @@ func getLatest(repo string, verbose bool) ([]string, error) {
|
||||
continue
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log(err)
|
||||
continue
|
||||
|
@ -1,7 +1,7 @@
|
||||
package generate
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -22,7 +22,7 @@ func TestDo(t *testing.T) {
|
||||
|
||||
tempDir := pathx.MustTempDir()
|
||||
typesfile := filepath.Join(tempDir, "types.go")
|
||||
err = ioutil.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
err = os.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = Do(&Context{
|
||||
@ -38,7 +38,7 @@ func TestDo(t *testing.T) {
|
||||
t.Run("missing config", func(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
typesfile := filepath.Join(tempDir, "types.go")
|
||||
err := ioutil.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
err := os.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = Do(&Context{
|
||||
@ -54,7 +54,7 @@ func TestDo(t *testing.T) {
|
||||
cfg := &config.Config{NamingFormat: "foo"}
|
||||
tempDir := t.TempDir()
|
||||
typesfile := filepath.Join(tempDir, "types.go")
|
||||
err := ioutil.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
err := os.WriteFile(typesfile, []byte(testTypes), 0o666)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = Do(&Context{
|
||||
|
@ -2,7 +2,6 @@ package command
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -76,12 +75,12 @@ func TestFromDDl(t *testing.T) {
|
||||
user1Sql := filepath.Join(tempDir, "user1.sql")
|
||||
user2Sql := filepath.Join(tempDir, "user2.sql")
|
||||
|
||||
err = ioutil.WriteFile(user1Sql, []byte(sql), os.ModePerm)
|
||||
err = os.WriteFile(user1Sql, []byte(sql), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(user2Sql, []byte(sql), os.ModePerm)
|
||||
err = os.WriteFile(user2Sql, []byte(sql), os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package migrationnotes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -24,7 +24,7 @@ func migrateBefore1_3_4(dir, style string) error {
|
||||
}
|
||||
|
||||
func needShow1_3_4(dir, style string) (bool, error) {
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package migrationnotes
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -18,15 +17,15 @@ func Test_needShow1_3_4(t *testing.T) {
|
||||
|
||||
dir1 := path.Join(root, "dir1")
|
||||
require.NoError(t, os.Mkdir(dir1, fs.ModePerm))
|
||||
ioutil.WriteFile(filepath.Join(dir1, "foo_gen.go"), nil, fs.ModePerm)
|
||||
os.WriteFile(filepath.Join(dir1, "foo_gen.go"), nil, fs.ModePerm)
|
||||
|
||||
dir2 := path.Join(root, "dir2")
|
||||
require.NoError(t, os.Mkdir(dir2, fs.ModePerm))
|
||||
ioutil.WriteFile(filepath.Join(dir2, "foomodel.go"), nil, fs.ModePerm)
|
||||
os.WriteFile(filepath.Join(dir2, "foomodel.go"), nil, fs.ModePerm)
|
||||
|
||||
dir3 := path.Join(root, "dir3")
|
||||
require.NoError(t, os.Mkdir(dir3, fs.ModePerm))
|
||||
ioutil.WriteFile(filepath.Join(dir3, "irrelevant.go"), nil, fs.ModePerm)
|
||||
os.WriteFile(filepath.Join(dir3, "irrelevant.go"), nil, fs.ModePerm)
|
||||
|
||||
type args struct {
|
||||
dir string
|
||||
|
@ -3,7 +3,6 @@ package gen
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -168,7 +167,7 @@ func (g *defaultGenerator) createFile(modelList map[string]*codeTuple) error {
|
||||
|
||||
name := util.SafeString(modelFilename) + "_gen.go"
|
||||
filename := filepath.Join(dirAbs, name)
|
||||
err = ioutil.WriteFile(filename, []byte(codes.modelCode), os.ModePerm)
|
||||
err = os.WriteFile(filename, []byte(codes.modelCode), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -179,7 +178,7 @@ func (g *defaultGenerator) createFile(modelList map[string]*codeTuple) error {
|
||||
g.Warning("%s already exists, ignored.", name)
|
||||
continue
|
||||
}
|
||||
err = ioutil.WriteFile(filename, []byte(codes.modelCustomCode), os.ModePerm)
|
||||
err = os.WriteFile(filename, []byte(codes.modelCustomCode), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package gen
|
||||
import (
|
||||
"database/sql"
|
||||
_ "embed"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -30,7 +29,7 @@ func TestCacheModel(t *testing.T) {
|
||||
_ = Clean()
|
||||
|
||||
sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql")
|
||||
err := ioutil.WriteFile(sqlFile, []byte(source), 0o777)
|
||||
err := os.WriteFile(sqlFile, []byte(source), 0o777)
|
||||
assert.Nil(t, err)
|
||||
|
||||
dir := filepath.Join(pathx.MustTempDir(), "./testmodel")
|
||||
@ -65,7 +64,7 @@ func TestNamingModel(t *testing.T) {
|
||||
_ = Clean()
|
||||
|
||||
sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql")
|
||||
err := ioutil.WriteFile(sqlFile, []byte(source), 0o777)
|
||||
err := os.WriteFile(sqlFile, []byte(source), 0o777)
|
||||
assert.Nil(t, err)
|
||||
|
||||
dir, _ := filepath.Abs("./testmodel")
|
||||
@ -103,7 +102,7 @@ func TestFolderName(t *testing.T) {
|
||||
_ = Clean()
|
||||
|
||||
sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql")
|
||||
err := ioutil.WriteFile(sqlFile, []byte(source), 0o777)
|
||||
err := os.WriteFile(sqlFile, []byte(source), 0o777)
|
||||
assert.Nil(t, err)
|
||||
|
||||
dir, _ := filepath.Abs("./testmodel")
|
||||
@ -179,7 +178,7 @@ func Test_genPublicModel(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
modelFilename := filepath.Join(modelDir, "foo.sql")
|
||||
err = ioutil.WriteFile(modelFilename, []byte(source), 0o777)
|
||||
err = os.WriteFile(modelFilename, []byte(source), 0o777)
|
||||
require.NoError(t, err)
|
||||
|
||||
g, err := NewDefaultGenerator(modelDir, &config.Config{
|
||||
|
@ -2,7 +2,7 @@ package parser
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestParsePlainText(t *testing.T) {
|
||||
sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql")
|
||||
err := ioutil.WriteFile(sqlFile, []byte("plain text"), 0o777)
|
||||
err := os.WriteFile(sqlFile, []byte("plain text"), 0o777)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = Parse(sqlFile, "go_zero", false)
|
||||
@ -24,7 +24,7 @@ func TestParsePlainText(t *testing.T) {
|
||||
|
||||
func TestParseSelect(t *testing.T) {
|
||||
sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql")
|
||||
err := ioutil.WriteFile(sqlFile, []byte("select * from user"), 0o777)
|
||||
err := os.WriteFile(sqlFile, []byte("select * from user"), 0o777)
|
||||
assert.Nil(t, err)
|
||||
|
||||
tables, err := Parse(sqlFile, "go_zero", false)
|
||||
@ -37,7 +37,7 @@ var user string
|
||||
|
||||
func TestParseCreateTable(t *testing.T) {
|
||||
sqlFile := filepath.Join(pathx.MustTempDir(), "tmp.sql")
|
||||
err := ioutil.WriteFile(sqlFile, []byte(user), 0o777)
|
||||
err := os.WriteFile(sqlFile, []byte(user), 0o777)
|
||||
assert.Nil(t, err)
|
||||
|
||||
tables, err := Parse(sqlFile, "go_zero", false)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
@ -13,7 +13,7 @@ func MatchFiles(in string) ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(abs)
|
||||
files, err := os.ReadDir(abs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,14 +3,14 @@ package format
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/parser"
|
||||
)
|
||||
|
||||
// File formats the api file.
|
||||
func File(filename string) error {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -18,7 +18,7 @@ func File(filename string) error {
|
||||
if err := Source(data, buffer); err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(filename, buffer.Bytes(), 0666)
|
||||
return os.WriteFile(filename, buffer.Bytes(), 0666)
|
||||
}
|
||||
|
||||
// Source formats the api source.
|
||||
|
@ -3,7 +3,7 @@ package parser
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -18,7 +18,7 @@ func Test_Parse(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("invalid", func(t *testing.T) {
|
||||
data, err := ioutil.ReadFile("./testdata/invalid.api")
|
||||
data, err := os.ReadFile("./testdata/invalid.api")
|
||||
assert.NoError(t, err)
|
||||
splits := bytes.Split(data, []byte("-----"))
|
||||
var testFile []string
|
||||
@ -29,7 +29,7 @@ func Test_Parse(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
filename := filepath.Join(t.TempDir(), fmt.Sprintf("invalid%d.api", idx))
|
||||
err := ioutil.WriteFile(filename, split, 0666)
|
||||
err := os.WriteFile(filename, split, 0666)
|
||||
assert.NoError(t, err)
|
||||
testFile = append(testFile, filename)
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@ -647,7 +647,7 @@ func NewScanner(filename string, src interface{}) (*Scanner, error) {
|
||||
}
|
||||
|
||||
func readData(filename string, src interface{}) ([]byte, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
data, err := os.ReadFile(filename)
|
||||
if err == nil {
|
||||
return data, nil
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -171,7 +170,7 @@ func downloadFile(filepath, url string) error {
|
||||
// NewPlugin returns contextual resources when written in other languages
|
||||
func NewPlugin() (*Plugin, error) {
|
||||
var plugin Plugin
|
||||
content, err := ioutil.ReadAll(os.Stdin)
|
||||
content, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package quickstart
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@ -38,7 +38,7 @@ func initRPCProto() error {
|
||||
|
||||
protoFilename := filepath.Join(zrpcWorkDir, protoName)
|
||||
rpcBytes := []byte(protocContent)
|
||||
return ioutil.WriteFile(protoFilename, rpcBytes, 0o666)
|
||||
return os.WriteFile(protoFilename, rpcBytes, 0o666)
|
||||
}
|
||||
|
||||
type micro struct{}
|
||||
@ -55,7 +55,7 @@ func (m micro) mustStartRPCProject() {
|
||||
arg := "goctl rpc protoc " + protoName + " --go_out=. --go-grpc_out=. --zrpc_out=. --verbose"
|
||||
execCommand(zrpcWorkDir, arg)
|
||||
etcFile := filepath.Join(zrpcWorkDir, "etc", "greet.yaml")
|
||||
logx.Must(ioutil.WriteFile(etcFile, []byte(rpcEtcContent), 0o666))
|
||||
logx.Must(os.WriteFile(etcFile, []byte(rpcEtcContent), 0o666))
|
||||
}
|
||||
|
||||
func (m micro) start() {
|
||||
|
@ -2,7 +2,7 @@ package quickstart
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@ -35,7 +35,7 @@ func initAPIFlags() error {
|
||||
|
||||
apiFilename := filepath.Join(apiWorkDir, "greet.api")
|
||||
apiBytes := []byte(apiContent)
|
||||
if err := ioutil.WriteFile(apiFilename, apiBytes, 0o666); err != nil {
|
||||
if err := os.WriteFile(apiFilename, apiBytes, 0o666); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ func (m mono) createAPIProject() {
|
||||
log.Debug(">> Generating quickstart api project...")
|
||||
logx.Must(gogen.GoCommand(nil, nil))
|
||||
etcFile := filepath.Join(apiWorkDir, "etc", "greet.yaml")
|
||||
logx.Must(ioutil.WriteFile(etcFile, []byte(apiEtcContent), 0o666))
|
||||
logx.Must(os.WriteFile(etcFile, []byte(apiEtcContent), 0o666))
|
||||
logicFile := filepath.Join(apiWorkDir, "internal", "logic", "pinglogic.go")
|
||||
svcFile := filepath.Join(apiWorkDir, "internal", "svc", "servicecontext.go")
|
||||
configPath := filepath.Join(apiWorkDir, "internal", "config")
|
||||
|
@ -2,7 +2,6 @@ package generator
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -36,5 +35,5 @@ func (g *Generator) GenConfig(ctx DirContext, _ parser.Proto, cfg *conf.Config)
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(fileName, []byte(text), os.ModePerm)
|
||||
return os.WriteFile(fileName, []byte(text), os.ModePerm)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -14,7 +13,7 @@ import (
|
||||
func Test_findPbFile(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
protoFile := filepath.Join(dir, "greet.proto")
|
||||
err := ioutil.WriteFile(protoFile, []byte(`
|
||||
err := os.WriteFile(protoFile, []byte(`
|
||||
syntax = "proto3";
|
||||
|
||||
package greet;
|
||||
|
@ -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)
|
||||
|
||||
|
@ -3,7 +3,7 @@ package util
|
||||
import (
|
||||
"bytes"
|
||||
goformat "go/format"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"text/template"
|
||||
|
||||
@ -50,7 +50,7 @@ func (t *DefaultTemplate) SaveTo(data any, path string, forceUpdate bool) error
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(path, output.Bytes(), regularPerm)
|
||||
return os.WriteFile(path, output.Bytes(), regularPerm)
|
||||
}
|
||||
|
||||
// Execute returns the codes after the template executed
|
||||
|
Loading…
Reference in New Issue
Block a user