Remove unused template init (fix startup crash)

The global template.Must parse at init time was left over from the
basic auth version. web.RenderTemplate handles parsing per-request.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-28 18:15:46 -07:00
parent 9db3883706
commit 131924520d

View File

@@ -4,9 +4,6 @@ import (
"context"
"database/sql"
"embed"
"fmt"
"html/template"
"log"
"net/http"
"strings"
@@ -29,33 +26,12 @@ var templateFiles embed.FS
//go:embed static
var staticFiles embed.FS
var templates = template.Must(template.ParseFS(templateFiles, "templates/*.html"))
type page struct {
Username string
Short string
URLs []*links.URL
}
func (srv *server) servePage(w http.ResponseWriter, p page, tpl string, funcs ...template.FuncMap) {
t := templates
if len(funcs) > 0 {
t = template.Must(t.Clone())
for _, fm := range funcs {
t.Funcs(fm)
}
// Re-parse to pick up the funcs.
t = template.Must(template.New("").Funcs(funcs[0]).ParseFS(templateFiles, "templates/*.html"))
}
err := t.ExecuteTemplate(w, tpl, p)
if err != nil {
log.Printf("error executing template: %s", err)
http.Error(w, fmt.Sprintf("template execution failed: %s", err.Error()),
http.StatusInternalServerError)
return
}
}
func (srv *server) handleLoginPage(w http.ResponseWriter, r *http.Request) {
web.RenderTemplate(w, templateFiles, "login.html", page{}, srv.csrf.TemplateFunc(w))
}