parent:
57cd687b81d1640c584c2673280ec456a5463380
nmyk <nick@nmyk.io>
2022-12-11T12:34:20-05:00
embeds tmpchat html templates
diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go
index b8cb7d2e4a1f4759367333cad9eb3adf829484d8..944a19b6d8fd3e0abc28649fc5f375d8c33a4717 100644
--- a/cmd/frontend/main.go
+++ b/cmd/frontend/main.go
@@ -1,21 +1,24 @@
package main
import (
- "fmt"
"html/template"
- "io/ioutil"
"log"
"net/http"
+ _ "embed"
+
"github.com/google/uuid"
"github.com/ianschenck/envflag"
)
-func getTemplate(desc string, funcMap template.FuncMap) *template.Template {
- t, _ := ioutil.ReadFile(
- fmt.Sprintf("templates/%s.gohtml", desc),
- )
- return template.Must(template.New(desc).Funcs(funcMap).Parse(string(t)))
+//go:embed templates/tmpchat-index.gohtml
+var tmpchatIndex string
+
+//go:embed templates/tmpchat-channel.gohtml
+var tmpchatChannel string
+
+func getTemplate(raw string, funcMap template.FuncMap) *template.Template {
+ return template.Must(template.New("").Funcs(funcMap).Parse(raw))
}
type tmpchatHandler struct {
@@ -29,9 +32,9 @@ fm := template.FuncMap{
"safeURL": func(u string) template.URL { return template.URL(u) },
}
if channelName == "" {
- tmpl = getTemplate("tmpchat-index", fm)
+ tmpl = getTemplate(tmpchatIndex, fm)
} else {
- tmpl = getTemplate("tmpchat-channel", fm)
+ tmpl = getTemplate(tmpchatChannel, fm)
}
userID := uuid.New().String()
d := tmpchatPageData{