From c072558b90f1bbedc2022b0f30c8b1ac4712538e Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Fri, 18 Feb 2011 09:50:58 +0100 Subject: Imported Upstream version 2011.02.15 --- doc/codelab/wiki/index.html | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'doc/codelab/wiki/index.html') diff --git a/doc/codelab/wiki/index.html b/doc/codelab/wiki/index.html index fe99c32d1..fc8c27bfa 100644 --- a/doc/codelab/wiki/index.html +++ b/doc/codelab/wiki/index.html @@ -573,7 +573,11 @@ redirect the client to the edit Page so the content may be created:

-func viewHandler(w http.ResponseWriter, r *http.Request, title string) {
+func viewHandler(w http.ResponseWriter, r *http.Request) {
+	title, err := getTitle(w, r)
+	if err != nil {
+		return
+	}
 	p, err := loadPage(title)
 	if err != nil {
 		http.Redirect(w, r, "/edit/"+title, http.StatusFound)
@@ -658,10 +662,14 @@ Now let's fix up saveHandler:
 

-func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
+func saveHandler(w http.ResponseWriter, r *http.Request) {
+	title, err := getTitle(w, r)
+	if err != nil {
+		return
+	}
 	body := r.FormValue("body")
 	p := &Page{Title: title, Body: []byte(body)}
-	err := p.save()
+	err = p.save()
 	if err != nil {
 		http.Error(w, err.String(), http.StatusInternalServerError)
 		return
@@ -702,7 +710,7 @@ Then we create an init function, which will be called before
 ParseFile that does not return an error code; instead, it panics
 if an error is encountered. A panic is appropriate here; if the templates can't
 be loaded the only sensible thing to do is exit the program.
-

 func init() {
@@ -726,7 +734,7 @@ the Execute method on the appropriate Template from
 
 
 func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
-	err := templates[tmpl].Execute(p, w)
+	err := templates[tmpl].Execute(w, p)
 	if err != nil {
 		http.Error(w, err.String(), http.StatusInternalServerError)
 	}
@@ -747,6 +755,7 @@ Then we can create a global variable to store our validation regexp:
 

+var titleValidator = regexp.MustCompile("^[a-zA-Z0-9]+$")
 

-- cgit v1.2.3