调整ioutil为go1.16推荐语法 (#1209)

* perf:根据go1.16后的提议修改包使用

* perf:根据go1.16后的提议修改包使用以及修改中间件的代码冗余
This commit is contained in:
XiaoK29
2022-08-29 15:40:40 +08:00
committed by GitHub
parent ed9ca764d4
commit 091b61bd10
9 changed files with 32 additions and 34 deletions

View File

@@ -1,7 +1,6 @@
package utils
import (
"io/ioutil"
"os"
"strconv"
)
@@ -75,7 +74,7 @@ func makeFileContent(content []byte, fileName string, FileDir string, contentNum
//@return: error, string
func MakeFile(fileName string, FileMd5 string) (string, error) {
rd, err := ioutil.ReadDir(breakpointDir + FileMd5)
rd, err := os.ReadDir(breakpointDir + FileMd5)
if err != nil {
return finishDir + fileName, err
}
@@ -86,7 +85,7 @@ func MakeFile(fileName string, FileMd5 string) (string, error) {
}
defer fd.Close()
for k := range rd {
content, _ := ioutil.ReadFile(breakpointDir + FileMd5 + "/" + fileName + "_" + strconv.Itoa(k))
content, _ := os.ReadFile(breakpointDir + FileMd5 + "/" + fileName + "_" + strconv.Itoa(k))
_, err = fd.Write(content)
if err != nil {
_ = os.Remove(finishDir + fileName)

View File

@@ -6,7 +6,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"strings"
)
@@ -28,7 +28,7 @@ const (
//@return: error
func AutoInjectionCode(filepath string, funcName string, codeData string) error {
srcData, err := ioutil.ReadFile(filepath)
srcData, err := os.ReadFile(filepath)
if err != nil {
return err
}
@@ -113,7 +113,7 @@ func AutoInjectionCode(filepath string, funcName string, codeData string) error
srcData = append(append(srcData[:indexPos], insertData...), remainData...)
// 写回数据
return ioutil.WriteFile(filepath, srcData, 0o600)
return os.WriteFile(filepath, srcData, 0o600)
}
func checkExist(srcData *[]byte, startPos int, endPos int, blockStmt *ast.BlockStmt, target string) bool {
@@ -153,7 +153,7 @@ func checkExist(srcData *[]byte, startPos int, endPos int, blockStmt *ast.BlockS
}
func AutoClearCode(filepath string, codeData string) error {
srcData, err := ioutil.ReadFile(filepath)
srcData, err := os.ReadFile(filepath)
if err != nil {
return err
}
@@ -161,7 +161,7 @@ func AutoClearCode(filepath string, codeData string) error {
if err != nil {
return err
}
return ioutil.WriteFile(filepath, srcData, 0o600)
return os.WriteFile(filepath, srcData, 0o600)
}
func cleanCode(clearCode string, srcData string) ([]byte, error) {

View File

@@ -45,6 +45,7 @@ func LoadPlugin(path string) error {
return err
}
if fileInfo.IsDir() {
// TODO 返回的参数不一样暂时不修改(https://golang.google.cn/doc/go1.16#ioutil)
fileSlice, err := ioutil.ReadDir(path)
if err != nil {
return err