fusenapi/utils/fstpl/auto_parse.go

42 lines
768 B
Go
Raw Normal View History

2023-09-04 03:32:17 +00:00
package fstpl
2023-09-04 04:30:24 +00:00
import (
"log"
"os"
"runtime"
"strings"
"text/template"
)
2023-09-04 03:32:17 +00:00
2023-09-04 04:30:24 +00:00
func AutoParseTplFiles() *template.Template {
2023-09-04 03:32:17 +00:00
2023-09-04 04:30:24 +00:00
var currentFilePath string
var ok bool
_, currentFilePath, _, ok = runtime.Caller(1)
if !ok {
panic("Error: Unable to get the current file path.")
}
dirs := strings.Split(currentFilePath, "/")
dirs = dirs[0 : len(dirs)-1]
var curdir string
for i := 0; i < 20; i++ {
curdir = strings.Join(dirs, "/")
finfo, err := os.Stat(curdir + "/fs_template")
//TODO: 完成
if err == nil && finfo.IsDir() {
tpls, err := template.ParseGlob(curdir + "/fs_template/*.tpl")
if err != nil {
log.Fatal(err)
}
return tpls
}
// log.Println(finfo, err)
dirs = dirs[:len(dirs)-1]
}
panic("can't find template dirs")
2023-09-04 03:32:17 +00:00
}