diff options
Diffstat (limited to 'website.go')
| -rw-r--r-- | website.go | 37 |
1 files changed, 37 insertions, 0 deletions
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) + } +} |
