当我从除 main 之外的其他 go 文件访问文件时,如何处理文件路径。
\n在 other.go 文件中,我尝试运行 ParseFS,但它给出了 template:pattern matches no files:templates/test.tmpl错误。这是我的文件树。
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 go.mod\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.go\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 other\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 other.go\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 templates\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test.tmpl\nRun Code Online (Sandbox Code Playgroud)\n其他/其他.go
\npackage other\n\nimport (\n "embed"\n "fmt"\n "html/template"\n)\n\nvar templateFS embed.FS\n\nfunc Check() error {\n _, err := template.New("email").ParseFS(templateFS, "templates/"+ "test.tmpl")\n\n if err != nil {\n fmt.Println(err)\n }\n return nil\n}\nRun Code Online (Sandbox Code Playgroud)\n主/main.go
\nfunc main() {\n err :=othher.Check()\n\n if err != nil {\n fmt.Println(err)\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n