package server import ( "embed" "net/http" "github.com/a-h/templ" "git.bronku.xyz/bronku/cake-order-tracker/store" ) type fetcher func(r *http.Request) (templ.Component, int, error) type Server struct { s *store.Store http.Handler } //go:embed static/* var static embed.FS func redirect(path string, code int) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, path, code) } } func New(store *store.Store) *Server { var server Server server.s = store mux := http.NewServeMux() mux.HandleFunc("GET /", redirect("/orders", http.StatusSeeOther)) mux.HandleFunc("GET /order/", server.render(server.order)) mux.HandleFunc("GET /orders", server.render(server.orders)) mux.HandleFunc("GET /cake/", server.render(server.cake)) mux.HandleFunc("GET /cakes", server.render(server.cakes)) mux.HandleFunc("POST /order/", server.render(server.postOrder)) mux.HandleFunc("POST /order/{id}/status", server.render(server.updateStatus)) mux.HandleFunc("POST /cake/", server.render(server.postCake)) mux.HandleFunc("GET /blocked", server.render(server.blocked)) mux.HandleFunc("POST /blocked", server.render(server.postBlocked)) mux.HandleFunc("POST /blocked/{id}/delete", server.render(server.deleteBlocked)) fs := http.FileServerFS(static) mux.Handle("GET /static/", fs) server.Handler = mux return &server }