all repos — captcha @ 0052db45f8f49f85e2d405951d3dd4c99079224e

Go package captcha implements generation and verification of image and audio CAPTCHAs.

example: use io instead of fmt; add error handling.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 21:32:16 +0200
commit

0052db45f8f49f85e2d405951d3dd4c99079224e

parent

885d67a665b23fc74a79bbcfd12093c8a0acae6c

1 files changed, 7 insertions(+), 4 deletions(-)

jump to
M example/main.goexample/main.go

@@ -2,9 +2,10 @@ // example of HTTP server that uses the captcha package.

package main import ( - "fmt" "github.com/dchest/captcha" "http" + "io" + "log" "template" )

@@ -25,17 +26,19 @@ }

func processFormHandler(w http.ResponseWriter, r *http.Request) { if !captcha.VerifyString(r.FormValue("captchaId"), r.FormValue("captchaSolution")) { - fmt.Fprintf(w, "Wrong captcha solution! No robots allowed!") + io.WriteString(w, "Wrong captcha solution! No robots allowed!\n") return } - fmt.Fprintf(w, "Great job, human! You solved the captcha.") + io.WriteString(w, "Great job, human! You solved the captcha.\n") } func main() { http.HandleFunc("/", showFormHandler) http.HandleFunc("/process", processFormHandler) http.Handle("/captcha/", captcha.Server(captcha.StdWidth, captcha.StdHeight)) - http.ListenAndServe(":8080", nil) + if err := http.ListenAndServe(":8080", nil); err != nil { + log.Fatal(err) + } } const formJavaScript = `