From 8bf5d9d2c82560c81be6809522215bded0cf9911 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 16 Feb 2016 18:43:22 +0100 Subject: Inital import --- index.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 index.go (limited to 'index.go') 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"))) +} -- cgit v1.2.3