我正在制作一個 webapp,我正在嘗試views/layouts/*.html
使用兩個 var 撰寫,但 filepath.Join 只給出views/layouts而不是views/layouts/
var (
LayoutDir string = filepath.Join("views","layouts")
TemplateExt string = "*.html"
)
然后打電話
f, err:= filepath.Glob(LayoutDir TemplateExt)
所以 f 包含views/layouts*.html而不是views/layouts/*.html
我應該如何解決這個問題,在這種情況下使用 filepath.Join 是一個好習慣嗎?
uj5u.com熱心網友回復:
f, err:= filepath.Glob(filepath.Join(LayoutDir, TemplateExt))應該做的伎倆
或者
LayoutDir string = filepath.Join("views", "layouts") string(filepath.Separator)
或者
LayoutDir string = filepath.Join("views", "layouts") string(os.PathSeparator)
uj5u.com熱心網友回復:
我沒有足夠的代表發表評論——也許模組會將我的“答案”轉移到評論中。要注意的一件快速的事情是這段代碼將views/layouts\在 Windows 機器上生成......我只是使用/而不是 filepath.Separator 或 os.PathSeparator。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/463405.html
