summary refs log tree commit diff homepage
path: root/main.go
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-05-31 15:24:35 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-05-31 15:24:35 +0900
commitc2cb66ad1830d1394c5d6c1dfa2e75ef7e23072b (patch)
treef95a3ae89ccc4e7f5c8cb6f023d055e422df479a /main.go
downloadphylactery-c2cb66ad1830d1394c5d6c1dfa2e75ef7e23072b.tar.gz
Draft web server skeleton
Diffstat (limited to 'main.go')
-rw-r--r--main.go30
1 files changed, 30 insertions, 0 deletions
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))
+}