From 57af2bcb9b2079ea86b256eb43241e85c6329406 Mon Sep 17 00:00:00 2001 From: Warwick New Date: Fri, 21 Feb 2025 19:08:14 +0000 Subject: [PATCH] initial templ commit --- .gitignore | 2 ++ go.mod | 5 +++++ go.sum | 4 ++++ main.go | 36 ++++++++++++++++++++++++++++++++++++ root.templ | 6 ++++++ 5 files changed, 53 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 root.templ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a17cdc1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +fedipod +**_templ.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4d8f9ac --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module fedipod + +go 1.23.6 + +require github.com/a-h/templ v0.3.833 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..bbe292f --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/a-h/templ v0.3.833 h1:L/KOk/0VvVTBegtE0fp2RJQiBm7/52Zxv5fqlEHiQUU= +github.com/a-h/templ v0.3.833/go.mod h1:cAu4AiZhtJfBjMY0HASlyzvkrtjnHWPeEsyGK2YYmfk= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/main.go b/main.go new file mode 100644 index 0000000..4d5c45a --- /dev/null +++ b/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "errors" + "fmt" + "github.com/a-h/templ" + "io" + "net/http" + "os" +) + +func getRoot(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Got / request\n") + io.WriteString(w, "Website root page\n") +} + +func getHello(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Got /hello request\n") + io.WriteString(w, "hello HTTP\n") +} + +func main() { + + component := root() + + mux := http.NewServeMux() + mux.Handle("/", templ.Handler(component)) + + err := http.ListenAndServe(":3000", mux) + if errors.Is(err, http.ErrServerClosed) { + fmt.Printf("server closed\n") + } else if err != nil { + fmt.Printf("error starting server: %s\n", err) + os.Exit(1) + } +} diff --git a/root.templ b/root.templ new file mode 100644 index 0000000..e707c8b --- /dev/null +++ b/root.templ @@ -0,0 +1,6 @@ +package main + +templ root() { +
Hello HTTP
+} +