mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 09:00:10 +00:00
router: correctly use local FS for custom HTML
This commit is contained in:
parent
11eae035d9
commit
9df2a82b6d
24
router.go
24
router.go
@ -24,19 +24,29 @@ func (app *appContext) loadHTML(router *gin.Engine) {
|
||||
app.err.Fatalf("Couldn't access template directory: \"%s\"", templatePath)
|
||||
return
|
||||
}
|
||||
loadFiles := make([]string, len(htmlFiles))
|
||||
for i, f := range htmlFiles {
|
||||
loadInternal := []string{}
|
||||
loadExternal := []string{}
|
||||
for _, f := range htmlFiles {
|
||||
if _, err := os.Stat(filepath.Join(customPath, f.Name())); os.IsNotExist(err) {
|
||||
app.debug.Printf("Using default \"%s\"", f.Name())
|
||||
loadFiles[i] = FSJoin(templatePath, f.Name())
|
||||
loadInternal = append(loadInternal, FSJoin(templatePath, f.Name()))
|
||||
} else {
|
||||
app.info.Printf("Using custom \"%s\"", f.Name())
|
||||
loadFiles[i] = filepath.Join(filepath.Join(customPath, f.Name()))
|
||||
loadExternal = append(loadExternal, filepath.Join(filepath.Join(customPath, f.Name())))
|
||||
}
|
||||
}
|
||||
tmpl, err := template.ParseFS(localFS, loadFiles...)
|
||||
if err != nil {
|
||||
app.err.Fatalf("Failed to load templates: %v", err)
|
||||
var tmpl *template.Template
|
||||
if len(loadInternal) != 0 {
|
||||
tmpl, err = template.ParseFS(localFS, loadInternal...)
|
||||
if err != nil {
|
||||
app.err.Fatalf("Failed to load templates: %v", err)
|
||||
}
|
||||
}
|
||||
if len(loadExternal) != 0 {
|
||||
tmpl, err = tmpl.ParseFiles(loadExternal...)
|
||||
if err != nil {
|
||||
app.err.Fatalf("Failed to load external templates: %v", err)
|
||||
}
|
||||
}
|
||||
router.SetHTMLTemplate(tmpl)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user