mirror of https://github.com/gin-gonic/gin.git
Add `Engine.LoadHTMLFromFS()` method to support `go:embed`
This commit is contained in:
parent
87e40d6b15
commit
ad70fbf73a
18
gin.go
18
gin.go
|
@ -7,6 +7,7 @@ package gin
|
|||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -267,6 +268,23 @@ func (engine *Engine) LoadHTMLFiles(files ...string) {
|
|||
engine.SetHTMLTemplate(templ)
|
||||
}
|
||||
|
||||
|
||||
// LoadHTMLFromFS loads HTML files identified by glob pattern
|
||||
// from a filesytem interface and associates the result with HTML renderer.
|
||||
func (engine *Engine) LoadHTMLFromFS(filesystem fs.FS, patterns ...string) {
|
||||
left := engine.delims.Left
|
||||
right := engine.delims.Right
|
||||
templ := template.Must(template.New("").Delims(left, right).Funcs(engine.FuncMap).ParseFS(filesystem, patterns...))
|
||||
|
||||
if IsDebugging() {
|
||||
debugPrintLoadTemplate(templ)
|
||||
engine.HTMLRender = render.HTMLDebug{Glob: pattern, FuncMap: engine.FuncMap, Delims: engine.delims}
|
||||
return
|
||||
}
|
||||
|
||||
engine.SetHTMLTemplate(templ)
|
||||
}
|
||||
|
||||
// SetHTMLTemplate associate a template with HTML renderer.
|
||||
func (engine *Engine) SetHTMLTemplate(templ *template.Template) {
|
||||
if len(engine.trees) > 0 {
|
||||
|
|
Loading…
Reference in New Issue