]> Cypherpunks repositories - gostls13.git/commitdiff
Codelab: correct function definitions for handlers before closures are introduced.
authorAndrey Mirtchovski <mirtchovski@gmail.com>
Mon, 7 Feb 2011 08:23:18 +0000 (09:23 +0100)
committerAndrew Gerrand <adg@golang.org>
Mon, 7 Feb 2011 08:23:18 +0000 (09:23 +0100)
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
doc/codelab/wiki/wiki.html

index fe99c32d1edc9b4f4c8ced0051011ce0c829dd9e..ee7af33442a3d011af52e8cf83376037d3f1a65a 100644 (file)
@@ -573,7 +573,11 @@ redirect the client to the edit Page so the content may be created:
 </p>
 
 <pre>
-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, &#34;/edit/&#34;+title, http.StatusFound)
@@ -658,10 +662,14 @@ Now let's fix up <code>saveHandler</code>:
 </p>
 
 <pre>
-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(&#34;body&#34;)
        p := &amp;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:
 </p>
 
 <pre>
+var titleValidator = regexp.MustCompile(&#34;^[a-zA-Z0-9]+$&#34;)
 </pre>
 
 <p>
index ff2c3088b0169a8945cdf1a170d8cdd4aba70c9c..3ddbd96b775b54cafb42545e88c17b68ece6f4c4 100644 (file)
@@ -477,7 +477,7 @@ redirect the client to the edit Page so the content may be created:
 </p>
 
 <pre>
-!./srcextract.bin -src=final.go -name=viewHandler
+!./srcextract.bin -src=final-noclosure.go -name=viewHandler
 </pre>
 
 <p>
@@ -539,7 +539,7 @@ Now let's fix up <code>saveHandler</code>:
 </p>
 
 <pre>
-!./srcextract.bin -src=final.go -name=saveHandler
+!./srcextract.bin -src=final-noclosure.go -name=saveHandler
 </pre>
 
 <p>
@@ -610,7 +610,7 @@ Then we can create a global variable to store our validation regexp:
 </p>
 
 <pre>
-!./srcextract.bin -src=final-noclosure.go -name=TitleValidator
+!./srcextract.bin -src=final-noclosure.go -name=titleValidator
 </pre>
 
 <p>