From 64d2a7c8945ba05af859901f5e248f1befdd8621 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 3 Dec 2013 09:43:15 +0100 Subject: Imported Upstream version 1.2 --- doc/articles/wiki/part3-errorhandling.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'doc/articles/wiki/part3-errorhandling.go') 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() -- cgit v1.2.3