Skip to content

Commit d468e2b

Browse files
liruohrhLinkinStars
authored andcommitted
feat: add env for glob load template files by gin debug render
1 parent 57ba299 commit d468e2b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

internal/base/server/http.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package server
2222
import (
2323
"html/template"
2424
"io/fs"
25+
"os"
2526

2627
brotli "github.com/anargu/gin-brotli"
2728
"github.com/apache/answer/internal/base/middleware"
@@ -53,9 +54,14 @@ func NewHTTPServer(debug bool,
5354
r.Use(brotli.Brotli(brotli.DefaultCompression), middleware.ExtractAndSetAcceptLanguage, shortIDMiddleware.SetShortIDFlag())
5455
r.GET("/healthz", func(ctx *gin.Context) { ctx.String(200, "OK") })
5556

56-
html, _ := fs.Sub(ui.Template, "template")
57-
htmlTemplate := template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*"))
58-
r.SetHTMLTemplate(htmlTemplate)
57+
templatePath := os.Getenv("ANSWER_TEMPLATE_PATH")
58+
if templatePath != "" {
59+
r.LoadHTMLGlob(templatePath)
60+
} else {
61+
html, _ := fs.Sub(ui.Template, "template")
62+
htmlTemplate := template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*"))
63+
r.SetHTMLTemplate(htmlTemplate)
64+
}
5965
r.Use(middleware.HeadersByRequestURI())
6066
viewRouter.Register(r, uiConf.BaseURL)
6167

0 commit comments

Comments
 (0)