all repos — captcha @ 9de0d066b9199eb378005dfef151c0dcfb81da7f

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

Add ErrNotFound, return it from WriteAudio/Image.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 14:34:11 +0200
commit

9de0d066b9199eb378005dfef151c0dcfb81da7f

parent

68d217e79dfab952ad179041ac11e1efaf071d3a

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

jump to
M captcha.gocaptcha.go

@@ -11,6 +11,8 @@

// Standard number of digits in captcha. const StdLength = 6 +var ErrNotFound = os.NewError("captcha with the given id not found") + var globalStore = newStore() // RandomDigits returns a byte slice of the given length containing random

@@ -54,7 +56,7 @@ // given id. The image will have the given width and height.

func WriteImage(w io.Writer, id string, width, height int) os.Error { d := globalStore.getDigits(id) if d == nil { - return os.NewError("captcha id not found") + return ErrNotFound } _, err := NewImage(d, width, height).WriteTo(w) return err

@@ -65,7 +67,7 @@ // given id.

func WriteAudio(w io.Writer, id string) os.Error { d := globalStore.getDigits(id) if d == nil { - return os.NewError("captcha id not found") + return ErrNotFound } _, err := NewAudio(d).WriteTo(w) return err