aboutsummaryrefslogtreecommitdiff
path: root/view.go
diff options
context:
space:
mode:
Diffstat (limited to 'view.go')
-rw-r--r--view.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/view.go b/view.go
new file mode 100644
index 0000000..62f9a4b
--- /dev/null
+++ b/view.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "net/http"
+ "text/template"
+)
+
+func init() {
+ http.HandleFunc("/view/", viewHandler)
+}
+
+func viewHandler(w http.ResponseWriter, r *http.Request) {
+ title := r.URL.Path[len("/view/"):]
+ p, err := loadPage(title)
+ if err != nil {
+ http.Redirect(w, r, "/edit/"+title, http.StatusFound)
+ return
+ }
+
+ p.HTML = parse(p.Body)
+ p.render(w, template.Must(template.ParseFiles("tmpl/root", "tmpl/view")))
+}