第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Go 中動態(tài)調(diào)用 template.ParseFiles() 而不是傳入 x 個字符串

在 Go 中動態(tài)調(diào)用 template.ParseFiles() 而不是傳入 x 個字符串

Go
不負相思意 2021-11-08 09:58:19
我想在 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貢獻1803條經(jīng)驗 獲得超3個贊

使用ParseGlob在一個 API 調(diào)用中解析 HTML 模板文件夾。

templates = template.Must(template.ParseGlob("../web/html_templates/*.html"))

有關(guān)glob 語法,請參閱匹配函數(shù)文檔。


查看完整回答
反對 回復 2021-11-08
?
莫回無

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...))


查看完整回答
反對 回復 2021-11-08
  • 2 回答
  • 0 關(guān)注
  • 217 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號