diff --git a/html_template/email_register.tpl b/fs_template/email_register.tpl similarity index 100% rename from html_template/email_register.tpl rename to fs_template/email_register.tpl diff --git a/server/auth/internal/logic/email_manager.go b/server/auth/internal/logic/email_manager.go index 5cefe8c3..a0c86349 100644 --- a/server/auth/internal/logic/email_manager.go +++ b/server/auth/internal/logic/email_manager.go @@ -3,6 +3,7 @@ package logic import ( "bytes" "fusenapi/utils/check" + "fusenapi/utils/fstpl" "log" "net/smtp" "sync" @@ -21,7 +22,7 @@ var tpls *template.Template func init() { var err error - tpls, err = template.ParseGlob("../../../../html_template/*.tpl") + tpls = fstpl.AutoParseTplFiles() if err != nil { log.Fatal(err) } diff --git a/utils/fstpl/auto_parse.go b/utils/fstpl/auto_parse.go index 347e3ff1..9bd69850 100644 --- a/utils/fstpl/auto_parse.go +++ b/utils/fstpl/auto_parse.go @@ -1,7 +1,41 @@ package fstpl -import "html/template" +import ( + "log" + "os" + "runtime" + "strings" + "text/template" +) -func ParseFile(t *template.Template) { +func AutoParseTplFiles() *template.Template { + 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") } diff --git a/utils/fstpl/auto_parse_test.go b/utils/fstpl/auto_parse_test.go new file mode 100644 index 00000000..f76d6b1d --- /dev/null +++ b/utils/fstpl/auto_parse_test.go @@ -0,0 +1,11 @@ +package fstpl + +import ( + "log" + "testing" +) + +func TestF(t *testing.T) { + + log.Println(AutoParseTplFiles()) +}