1 Star 3 Fork 4

海风/gotap_dipper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
package generate
import (
"bytes"
"os"
"path"
"text/template"
)
// var srcPath = "../v9.3.7.5_20220228"
var srcPath = []string{"../v9.3.8.7_20230117", "quote_v9.3.1.4_20190925"}
// readFile 文件先手动转为 UTF8
//
// @param fileNames
// @return string
func readFile(fileNames ...string) string {
var str string
for _, fileName := range fileNames {
var fileFullPath string
for _, v := range srcPath {
if _, err := os.Stat(path.Join(v, fileName)); err == nil {
fileFullPath = path.Join(v, fileName)
break
}
}
bs, err := os.ReadFile(fileFullPath)
if err != nil {
panic(err)
}
str += string(bs)
}
return str
}
func writeTmpl(tplFile string, writeToFile string, data any, funcMaps ...template.FuncMap) {
var err error
t := template.New(tplFile).Delims("[[", "]]")
// funcMap 加入 Funcs
for _, fm := range funcMaps {
t = t.Funcs(fm)
}
if t, err = t.ParseFiles(tplFile); err != nil {
panic(err)
}
buf := bytes.Buffer{}
if err = t.Execute(&buf, data); err != nil {
panic(err)
}
// 解决 & 生成tmp 后多出的 amp;
// 用 text/template 替代 html/template 解决
// bs := buf.Bytes()
// bs = bytes.ReplaceAll(bs, []byte("amp;"), []byte(""))
if err = os.WriteFile(writeToFile, buf.Bytes(), os.ModePerm); err != nil {
panic(err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/haifengat/gotap_dipper.git
git@gitee.com:haifengat/gotap_dipper.git
haifengat
gotap_dipper
gotap_dipper
master

搜索帮助