Embed template files in server binary

This commit is contained in:
2024-08-01 00:42:35 -04:00
parent 5adfeefa33
commit 1d6e8a9811
3 changed files with 22 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"html/template"
"io"
"io/fs"
"log"
"net/http"
)
@@ -34,6 +35,15 @@ func FromFile(filepath string) (Template, error) {
htmlTpl: tpl,
}, nil
}
func FromFS(fs fs.FS, pattern string) (Template, error) {
tpl, err := template.ParseFS(fs, pattern)
if err != nil {
return Template{}, fmt.Errorf("Error parsing template: %v", err)
}
return Template{
htmlTpl: tpl,
}, nil
}
func Must(t Template, err error) Template {
if err != nil {