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:
24
handler.go
24
handler.go
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user