mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-10-07 22:59:59 +00:00
feat:Routes are added directly to the structure
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user