aboutsummaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
Diffstat (limited to 'index.go')
-rw-r--r--index.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/index.go b/index.go
new file mode 100644
index 0000000..a9613fd
--- /dev/null
+++ b/index.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "io/ioutil"
+ "net/http"
+ "text/template"
+)
+
+func init() {
+ http.HandleFunc("/index", indexHandler)
+}
+
+func indexHandler(w http.ResponseWriter, r *http.Request) {
+ files, err := ioutil.ReadDir("data")
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ p := new(Page)
+ for _, entry := range files {
+ file := entry.Name()
+ if !entry.IsDir() && file[0] != '.' {
+ p.Pages = append(p.Pages, file)
+ }
+ }
+ p.render(w, template.Must(template.ParseFiles("tmpl/root", "tmpl/index")))
+}