aboutsummaryrefslogtreecommitdiff
path: root/view.go
blob: 3a1c47a26854420f5fe3f1f5a2bcdc023d439d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

import (
	"net/http"
	"text/template"
)

func init() {
	http.HandleFunc("/view/", viewHandler)
}

var viewtmpl = template.Must(template.ParseFiles("tmpl/root", "tmpl/view"))

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.render(w, viewtmpl)
}