goview
goview copied to clipboard
Embeded Static file support on golang 1.16 standard Example
I see issue #9 that you have support on go.rice https://github.com/foolin/goview/issues/9 do you have plan to support go embeded or do you have example to do it? https://golang.org/pkg/embed/
If you've a file layout with like, ui/index.html and ui/whatever.html, you can do this:
//go:embed ui/*
var ui embed.FS
func embeddedFH(config goview.Config, tmpl string) (string, error) {
path := filepath.Join(config.Root, tmpl)
bytes, err := ui.ReadFile(path + config.Extension)
return string(bytes), err
}
func main() {
//new template engine
gv := ginview.New(
goview.Config{
Root: "ui",
Extension: ".html",
},
)
gv.ViewEngine.SetFileHandler(embeddedFH)
router.HTMLRender = gv
}
And it'll render from your embedded assets.