all repos — captcha @ 5c81f018db7f2dfe408cb07e07151cf7a8af14b9

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

Use new GitHub-flavored Markdown syntax for types.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 15:22:52 +0200
commit

5c81f018db7f2dfe408cb07e07151cf7a8af14b9

parent

31e7bb63c9e1638e6c34ec1d9428cdf6f3bccbdb

1 files changed, 55 insertions(+), 37 deletions(-)

jump to
M README.mdREADME.md

@@ -12,30 +12,34 @@

Constants --------- - const ( - // Standard number of digits in captcha. - StdLength = 6 - // The number of captchas created that triggers garbage collection used - // by default store. - CollectNum = 100 - // Expiration time of captchas used by default store. - Expiration = 10 * 60 // 10 minutes - - ) - +``` go +const ( + // Standard number of digits in captcha. + StdLength = 6 + // The number of captchas created that triggers garbage collection used + // by default store. + CollectNum = 100 + // Expiration time of captchas used by default store. + Expiration = 10 * 60 // 10 minutes - const ( - // Standard width and height of a captcha image. - StdWidth = 300 - StdHeight = 80 - ) +) +``` +``` go +const ( + // Standard width and height of a captcha image. + StdWidth = 300 + StdHeight = 80 +) +``` Variables --------- - var ErrNotFound = os.NewError("captcha with the given id not found") +``` go +var ErrNotFound = os.NewError("captcha with the given id not found") +```

@@ -141,10 +145,12 @@

Types ----- - type Audio struct { +``` go +type Audio struct { // contains unexported fields } - +``` + ### func NewAudio

@@ -166,11 +172,13 @@

WriteTo writes captcha audio in WAVE format into the given io.Writer, and returns the number of bytes written and an error if any. - type Image struct { - *image.NRGBA - // contains unexported fields - } - +``` go +type Image struct { + *image.NRGBA + // contains unexported fields +} +``` + ### func NewImage

@@ -185,21 +193,23 @@ func (img *Image) WriteTo(w io.Writer) (int64, os.Error)

WriteTo writes captcha image in PNG format into the given writer. - type Store interface { - // Set sets the digits for the captcha id. - Set(id string, digits []byte) +``` go +type Store interface { + // Set sets the digits for the captcha id. + Set(id string, digits []byte) - // Get returns stored digits for the captcha id. Clear indicates - // whether the captcha must be deleted from the store. - Get(id string, clear bool) (digits []byte) + // Get returns stored digits for the captcha id. Clear indicates + // whether the captcha must be deleted from the store. + Get(id string, clear bool) (digits []byte) - // Collect deletes expired captchas from the store. For custom stores - // this method is not called automatically, it is only wired to the - // package's Collect function. Custom stores must implement their own - // procedure for calling Collect, for example, in Set method. - Collect() - } - + // Collect deletes expired captchas from the store. For custom stores + // this method is not called automatically, it is only wired to the + // package's Collect function. Custom stores must implement their own + // procedure for calling Collect, for example, in Set method. + Collect() +} +``` + An object implementing Store interface can be registered with SetCustomStore function to handle storage and retrieval of captcha ids and solutions for them, replacing the default memory store.

@@ -224,3 +234,11 @@

While Image conforms to io.WriterTo interface, its WriteTo method returns 0 instead of the actual bytes written because png.Encode doesn't report this. + + +Subdirectories +-------------- + +capgen +example +generate