aboutsummaryrefslogtreecommitdiff
path: root/view.go
blob: aae362e0cbf86118bcf39535445f4ad7c6636bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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.render(w, template.Must(template.ParseFiles("tmpl/root", "tmpl/view")))
}