feat:Routes are added directly to the structure

This commit is contained in:
wenjianzhang
2020-07-22 18:08:39 +08:00
parent 563b7ea10c
commit bad111a633
3 changed files with 73 additions and 10 deletions
+45
View File
@@ -4,6 +4,7 @@ import (
"archive/zip"
"bytes"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
@@ -112,3 +113,47 @@ func FileZip(dst, src string,notContPath string) (err error) {
return nil
})
}
type ReplaceHelper struct {
Root string //路径
OldText string //需要替换的文本
NewText string //新的文本
}
func (h *ReplaceHelper) DoWrok() error {
return filepath.Walk(h.Root, h.walkCallback)
}
func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error {
if err != nil {
return err
}
if f == nil {
return nil
}
if f.IsDir() {
log.Println("DIR:",path)
return nil
}
//文件类型需要进行过滤
buf, err := ioutil.ReadFile(path)
if err != nil {
//err
return err
}
content := string(buf)
log.Printf("h.OldText: %s \n",h.OldText)
log.Printf("h.NewText: %s \n",h.NewText)
//替换
newContent := strings.Replace(content, h.OldText, h.NewText, -1)
//重新写入
ioutil.WriteFile(path, []byte(newContent), 0)
return err
}