我想在 Go 中加載一個 HTML 模板文件夾,現(xiàn)在我只能將每個文件路徑作為參數(shù)中的字符串傳遞。例子:templates = template.Must(template.ParseFiles("../web/html_templates/edit.html","../web/html_mplates/view.html"))工作正常。這個和類似的解決方案將不起作用:templates = template.Must(template.ParseFiles("../web/html_templates/*"))我想在配置文件中指定我的模板,但我目前不能。解決這個問題的最佳方法是什么?
2 回答

莫回無
TA貢獻1865條經(jīng)驗 獲得超7個贊
您可以使用template.ParseFiles是一個可變參數(shù)函數(shù)這一事實:
var templatesFiles []string
// [...]
// Here fill the slice from your config file or any other source
// [...]
templates = template.Must(template.ParseFiles(templatesFiles...))
- 2 回答
- 0 關(guān)注
- 217 瀏覽
添加回答
舉報
0/150
提交
取消