From ba1be9573ef20d6424ae987257a1c727c47d4b53 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Tue, 6 Oct 2026 20:46:31 +0300 Subject: Initial setup for website rewrite --- website.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 website.go (limited to 'website.go') diff --git a/website.go b/website.go new file mode 100644 index 0000000..d1cf44d --- /dev/null +++ b/website.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "net/http" +) + +func main() { + fmt.Println("foo") + + mux := http.NewServeMux() + + fileServer := http.FileServer(http.Dir("./public")) + mux.Handle("GET /public/", http.StripPrefix("/public/", fileServer)) + + mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { + HomePage().Render(r.Context(), w) + }) + + mux.HandleFunc("GET /about", func(w http.ResponseWriter, r *http.Request) { + AboutPage().Render(r.Context(), w) + }) + + mux.HandleFunc("GET /items", func(w http.ResponseWriter, r *http.Request) { + data := []Item{ + {Name: "Foo", Active: true}, + {Name: "Bar", Active: true}, + {Name: "Baz", Active: false}, + } + ItemsPage(data).Render(r.Context(), w) + }) + + fmt.Println("Server running at http://localhost:8080") + if err := http.ListenAndServe(":8080", mux); err != nil { + panic(err) + } +} -- cgit v1.3.1