Embed template files in server binary
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user