From 46ef0bb906711dcfe6f94b89f049ec4f8e8e9f9a Mon Sep 17 00:00:00 2001 From: Tom Brereton Date: Wed, 10 Jan 2024 14:09:57 +1100 Subject: [PATCH] feat: add htmx demo --- internal/routes/htmx.go | 21 +++++++++++++++++++++ internal/server/server.go | 1 + templates/htmx-demo.html | 3 +++ templates/landing.html | 5 +++++ 4 files changed, 30 insertions(+) create mode 100644 internal/routes/htmx.go create mode 100644 templates/htmx-demo.html diff --git a/internal/routes/htmx.go b/internal/routes/htmx.go new file mode 100644 index 0000000..14fe694 --- /dev/null +++ b/internal/routes/htmx.go @@ -0,0 +1,21 @@ +package routes + +import ( + "html/template" + "net/http" + + "github.com/go-chi/chi/v5" +) + +func Htmx(t *template.Template) *chi.Mux { + r := chi.NewRouter() + + r.Get("/", func(w http.ResponseWriter, r *http.Request) { + err := t.ExecuteTemplate(w, "htmx-demo.html", nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + }) + + return r +} diff --git a/internal/server/server.go b/internal/server/server.go index b4ef333..089293c 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -47,6 +47,7 @@ func (s *Server) MountMiddleware() { func (s *Server) MountPageHandlers() { s.Router.NotFound(routes.NotFound(s.Templates)) s.Router.Mount("/", routes.LandingPage(s.Templates)) + s.Router.Mount("/clicked", routes.Htmx(s.Templates)) } func (s *Server) MountStaticFiles() { diff --git a/templates/htmx-demo.html b/templates/htmx-demo.html new file mode 100644 index 0000000..2eb67db --- /dev/null +++ b/templates/htmx-demo.html @@ -0,0 +1,3 @@ +{{ define "htmx-demo.html" }} +

Who needs SPA

+{{ end }} \ No newline at end of file diff --git a/templates/landing.html b/templates/landing.html index 727af05..ed19748 100644 --- a/templates/landing.html +++ b/templates/landing.html @@ -6,12 +6,17 @@ +

Hello, {{ .Name }}!

+ +