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 dmitry@codingrobots.com
Wed, 27 Apr 2011 15:54:27 +0200
1 files changed,
7 insertions(+),
2 deletions(-)
jump to
M
example/main.go
→
example/main.go
@@ -12,6 +12,10 @@
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 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() {