summaryrefslogtreecommitdiff
path: root/doc/articles/wiki/part3-errorhandling.go
diff options
context:
space:
mode:
Diffstat (limited to 'doc/articles/wiki/part3-errorhandling.go')
-rw-r--r--doc/articles/wiki/part3-errorhandling.go8
1 files changed, 3 insertions, 5 deletions
diff --git a/doc/articles/wiki/part3-errorhandling.go b/doc/articles/wiki/part3-errorhandling.go
index 945aa1e39..bb4ecda84 100644
--- a/doc/articles/wiki/part3-errorhandling.go
+++ b/doc/articles/wiki/part3-errorhandling.go
@@ -29,15 +29,13 @@ func loadPage(title string) (*Page, error) {
return &Page{Title: title, Body: body}, nil
}
-const lenPath = len("/view/")
-
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
t, _ := template.ParseFiles(tmpl + ".html")
t.Execute(w, p)
}
func viewHandler(w http.ResponseWriter, r *http.Request) {
- title := r.URL.Path[lenPath:]
+ title := r.URL.Path[len("/view/"):]
p, err := loadPage(title)
if err != nil {
http.Redirect(w, r, "/edit/"+title, http.StatusFound)
@@ -47,7 +45,7 @@ func viewHandler(w http.ResponseWriter, r *http.Request) {
}
func editHandler(w http.ResponseWriter, r *http.Request) {
- title := r.URL.Path[lenPath:]
+ title := r.URL.Path[len("/edit/"):]
p, err := loadPage(title)
if err != nil {
p = &Page{Title: title}
@@ -56,7 +54,7 @@ func editHandler(w http.ResponseWriter, r *http.Request) {
}
func saveHandler(w http.ResponseWriter, r *http.Request) {
- title := r.URL.Path[lenPath:]
+ title := r.URL.Path[len("/save/"):]
body := r.FormValue("body")
p := &Page{Title: title, Body: []byte(body)}
err := p.save()