all repos — captcha @ 4572d7de1ee5df2037b182041918d7490aa1f32d

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

Fix comments, apply gofmt.
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 22:49:14 +0200
commit

4572d7de1ee5df2037b182041918d7490aa1f32d

parent

11dc0126458902853ddfebd0c6f94fd3214beddb

5 files changed, 8 insertions(+), 11 deletions(-)

jump to
M audio.goaudio.go

@@ -13,9 +13,8 @@

const sampleRate = 8000 // Hz var ( - // Length of the longest digit sound. longestDigitSndLen int - endingBeepSound []byte + endingBeepSound []byte ) func init() {
M captcha.gocaptcha.go

@@ -11,10 +11,10 @@

const ( // Standard number of digits in captcha. StdLength = 6 - // The number of captchas created that triggers garbage collection + // The number of captchas created that triggers garbage collection. StdCollectNum = 100 - // Expiration time of captchas - StdExpiration = 2*60 // 2 minutes + // Expiration time of captchas. + StdExpiration = 2 * 60 // 2 minutes )

@@ -28,7 +28,7 @@ // digits in range 0-9.

func RandomDigits(length int) []byte { d := make([]byte, length) if _, err := io.ReadFull(rand.Reader, d); err != nil { - panic(err) + panic("error reading random source: " + err.String()) } for i := range d { d[i] %= 10

@@ -99,8 +99,7 @@ // storage. It is called automatically by New function every CollectNum

// generated captchas, but still exported to enable freeing memory manually if // needed. // -// Collection is launched in a new goroutine, so this function returns -// immediately. +// Collection is launched in a new goroutine. func Collect() { go globalStore.collect() }
M generate/main.gogenerate/main.go

@@ -67,7 +67,7 @@ log.Fatalf("%s", err)

} defer pcm.Close() fmt.Fprintf(pcm, `package captcha - + // This file has been generated from .wav files using generate.go. var waveHeader = []byte{
M image.goimage.go

@@ -40,7 +40,6 @@ uint8(rand.Intn(129)),

uint8(rand.Intn(129)), 0xFF, } - // Calculate sizes. img.calculateSizes(width, height, len(digits)) // Draw background (10 random circles of random brightness). img.fillWithCircles(10, img.dotSize)
M sounds.gosounds.go

@@ -1,5 +1,5 @@

package captcha - + // This file has been generated from .wav files using generate.go. var waveHeader = []byte{