39 lines
654 B
Go
39 lines
654 B
Go
package web
|
|
|
|
import (
|
|
"embed"
|
|
"encoding/json"
|
|
"html/template"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/gofiber/template/html"
|
|
)
|
|
|
|
//go:embed views/*
|
|
var viewsfs embed.FS
|
|
|
|
func ViewsEngine() *html.Engine {
|
|
engine := html.NewFileSystem(http.FS(viewsfs), ".html")
|
|
engine.AddFunc(
|
|
"unsafe", func(s string) template.HTML {
|
|
return template.HTML(s)
|
|
},
|
|
)
|
|
engine.AddFunc(
|
|
"queryEscape", func(s string) string {
|
|
return url.QueryEscape(s)
|
|
},
|
|
)
|
|
engine.AddFunc(
|
|
"jsonMarshal", func(s any) (string, error) {
|
|
j, err := json.MarshalIndent(s, "", " ")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(j), nil
|
|
},
|
|
)
|
|
return engine
|
|
}
|