loading all templates automatically

This commit is contained in:
Bronku 2025-01-31 16:56:12 +01:00
parent 9f858d50ae
commit f7498f4ef1
13 changed files with 128 additions and 105 deletions

24
handlers.go Normal file
View file

@ -0,0 +1,24 @@
package main
import (
"fmt"
"net/http"
)
func (c *controller) cakeOptions(w http.ResponseWriter, _ *http.Request) {
type cake struct {
Name string
ID int
}
c.tmpl["available_cakes"].Execute(w, struct{ Cakes []cake }{Cakes: []cake{{"Hello", 1}, {"World", 2}}})
}
func (c *controller) postNewOrder(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
_ = c.tmpl["confirm_order"].Execute(w, struct{ Status any }{Status: err})
}
w.WriteHeader(http.StatusAccepted)
fmt.Println(r.Form)
_ = c.tmpl["confirm_order"].Execute(w, struct{ Status any }{Status: r.Form})
}