Skip to content

Commit

Permalink
使用os包中的ReadFile、ReadDir,详情见golang/go#42026
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-debug110 committed Aug 9, 2022
1 parent 7d725c5 commit 7a1542c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 4 additions & 3 deletions core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"flag"
"fmt"
"gofound/global"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"runtime"

"gopkg.in/yaml.v2"
)

// Parser 解析器
Expand Down Expand Up @@ -40,7 +40,8 @@ func Parser() *global.Config {

if *configPath != "" {
//解析配置文件
file, err := ioutil.ReadFile(*configPath)
//file, err := ioutil.ReadFile(*configPath)
file, err := os.ReadFile(*configPath) //详情:https://github.com/golang/go/issues/42026
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions searcher/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package searcher
import (
"fmt"
"gofound/searcher/words"
"io/ioutil"
"log"
"os"
"runtime"
Expand All @@ -24,7 +23,7 @@ func (c *Container) Init() error {
c.engines = make(map[string]*Engine)

//读取当前路径下的所有目录,就是数据库名称
dirs, err := ioutil.ReadDir(c.Dir)
dirs, err := os.ReadDir(c.Dir)
if err != nil {
if os.IsNotExist(err) {
//创建
Expand Down
3 changes: 1 addition & 2 deletions searcher/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"encoding/gob"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -202,7 +201,7 @@ func ReleaseAssets(file fs.File, out string) {
}
}(outFile)

err = ioutil.WriteFile(out, buffer, os.ModePerm)
err = os.WriteFile(out, buffer, os.ModePerm)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 7a1542c

Please sign in to comment.