Browse Source

example: add "Try another one" link; ignore /xxx.

Only return page for root path /, return 404 for any other, such as
/favicon.ico.
Dmitry Chestnykh 14 years ago
parent
commit
a6788822d7
1 changed files with 7 additions and 2 deletions
  1. 7 2
      example/main.go

+ 7 - 2
example/main.go

@@ -12,6 +12,10 @@ import (
 var formTemplate = template.MustParse(formTemplateSrc, nil)
 
 func showFormHandler(w http.ResponseWriter, r *http.Request) {
+	if r.URL.Path != "/" {
+		http.NotFound(w, r)
+		return
+	}
 	d := struct {
 		CaptchaId  string
 		JavaScript string
@@ -27,9 +31,10 @@ func showFormHandler(w http.ResponseWriter, r *http.Request) {
 func processFormHandler(w http.ResponseWriter, r *http.Request) {
 	if !captcha.VerifyString(r.FormValue("captchaId"), r.FormValue("captchaSolution")) {
 		io.WriteString(w, "Wrong captcha solution! No robots allowed!\n")
-		return
+	} else {
+		io.WriteString(w, "Great job, human! You solved the captcha.\n")
 	}
-	io.WriteString(w, "Great job, human! You solved the captcha.\n")
+	io.WriteString(w, "<br><a href='/'>Try another one</a>")
 }
 
 func main() {