From 61c93cac3e25de0b57b83143e71a342d12a7d8ee Mon Sep 17 00:00:00 2001 From: Andrey Mirtchovski Date: Mon, 7 Feb 2011 09:23:18 +0100 Subject: [PATCH] Codelab: correct function definitions for handlers before closures are introduced. A couple of post-closure function definitions were introduced too early, making the resulting code fail compilation. Also, the TitleValidator regexp was missing. R=adg CC=golang-dev https://golang.org/cl/4105054 --- doc/codelab/wiki/index.html | 15 ++++++++++++--- doc/codelab/wiki/wiki.html | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/doc/codelab/wiki/index.html b/doc/codelab/wiki/index.html index fe99c32d1ed..ee7af33442a 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
@@ -747,6 +755,7 @@ Then we can create a global variable to store our validation regexp:
 

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

diff --git a/doc/codelab/wiki/wiki.html b/doc/codelab/wiki/wiki.html index ff2c3088b01..3ddbd96b775 100644 --- a/doc/codelab/wiki/wiki.html +++ b/doc/codelab/wiki/wiki.html @@ -477,7 +477,7 @@ redirect the client to the edit Page so the content may be created:

-!./srcextract.bin -src=final.go -name=viewHandler
+!./srcextract.bin -src=final-noclosure.go -name=viewHandler
 

@@ -539,7 +539,7 @@ Now let's fix up saveHandler:

-!./srcextract.bin -src=final.go -name=saveHandler
+!./srcextract.bin -src=final-noclosure.go -name=saveHandler
 

@@ -610,7 +610,7 @@ Then we can create a global variable to store our validation regexp:

-!./srcextract.bin -src=final-noclosure.go -name=TitleValidator
+!./srcextract.bin -src=final-noclosure.go -name=titleValidator