From c2cb66ad1830d1394c5d6c1dfa2e75ef7e23072b Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Tue, 31 May 2022 15:24:35 +0900 Subject: Draft web server skeleton --- main.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..656b816 --- /dev/null +++ b/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "embed" + "html/template" + "log" + "net/http" + "os" +) + +//go:embed static/* +var static embed.FS + +//go:embed templates/*.html +var templates embed.FS + +func main() { + http.Handle("/static/", http.FileServer(http.FS(static))) + t, err := template.ParseFS(templates, "templates/*.html") + if err != nil { + log.Fatal(err) + } + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + t.ExecuteTemplate(w, "index.html", "Phylactery") + }) + + addr := os.Getenv("PHYLACTERY_ADDRESS") + log.Println("Listening on", addr) + log.Fatal(http.ListenAndServe(addr, nil)) +} -- cgit 1.4.1