0
我想要一個func來掃描文件夾並找到所有的模板文件。然後調用template.ParseFiles來解析所有模板。我使用var tmplPathList []string
來記錄所有的模板,並通過tmplPathList
到template.ParseFiles()
。如何將[]字符串轉換爲...字符串
func ParseFiles(filenames ...string) (*Template, error)
使用... string
作爲參數。編譯錯誤cannot use tmplPathList (type []string) as type string in argument to "html/template".ParseFiles
如何將[]string
轉換爲... string
?
var tmplPathList []string
for _, file := range tmplList {
tmplPathList = append(tmplPathList, dir + file.Name())
}
templates = template.Must(template.ParseFiles(tmplPathList))
我知道有一種方法,並且你向我展示了簡單的方法。 – firelyu
@Flimzy這是我需要的。別再問問題了。 – firelyu