Refactor to ES module with localStorage profile and data-bind

This commit is contained in:
Ian Gulliver
2025-12-29 12:01:49 -08:00
parent cb8ec3ff7d
commit 4e4bb49e8c
3 changed files with 105 additions and 65 deletions

11
main.go
View File

@@ -21,7 +21,8 @@ var (
)
func init() {
templates = template.Must(template.ParseGlob("static/*.html"))
templates = template.Must(template.New("").ParseGlob("static/*.html"))
template.Must(templates.ParseGlob("static/*.js"))
var err error
db, err = sql.Open("postgres", os.Getenv("PGCONN"))
@@ -63,13 +64,17 @@ func handleStatic(w http.ResponseWriter, r *http.Request) {
name := strings.TrimPrefix(path, "/")
if strings.HasSuffix(name, ".html") {
if strings.HasSuffix(name, ".html") || strings.HasSuffix(name, ".js") {
t := templates.Lookup(name)
if t == nil {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "text/html")
if strings.HasSuffix(name, ".html") {
w.Header().Set("Content-Type", "text/html")
} else {
w.Header().Set("Content-Type", "application/javascript")
}
t.Execute(w, templateData())
return
}