Implement shared template layout system

This commit is contained in:
bronku 2025-03-29 07:33:23 +01:00
parent 3be7fb76e7
commit 08b669fd8f
9 changed files with 69 additions and 45 deletions

View file

@ -8,7 +8,7 @@ import (
)
type Server struct {
tmpl *template.Template
tmpl map[string]*template.Template
s *store.Store
http.Handler
}
@ -19,13 +19,13 @@ func (h *Server) Close() {
func (h *Server) loadHandler() {
mux := http.NewServeMux()
mux.HandleFunc("GET /order/", h.render(h.order, "order.html"))
mux.HandleFunc("GET /order/", h.render(h.order, "order"))
mux.HandleFunc("GET /", h.redirect("/orders", http.StatusSeeOther))
mux.HandleFunc("GET /orders", h.render(h.orders, "orders.html"))
mux.HandleFunc("POST /order/", h.render(h.postOrder, "confirmation.html"))
mux.HandleFunc("GET /cakes", h.render(h.cakes, "cakes.html"))
mux.HandleFunc("GET /cake/", h.render(h.cake, "cake.html"))
mux.HandleFunc("POST /cake/", h.render(h.postCake, "confirmation.html"))
mux.HandleFunc("GET /orders", h.render(h.orders, "orders"))
mux.HandleFunc("POST /order/", h.render(h.postOrder, "confirmation"))
mux.HandleFunc("GET /cakes", h.render(h.cakes, "cakes"))
mux.HandleFunc("GET /cake/", h.render(h.cake, "cake"))
mux.HandleFunc("POST /cake/", h.render(h.postCake, "confirmation"))
h.Handler = mux
}