diff --git a/pkg/captcha/captcha.go b/pkg/captcha/captcha.go index 17ddc61..8193e0c 100644 --- a/pkg/captcha/captcha.go +++ b/pkg/captcha/captcha.go @@ -20,7 +20,8 @@ func NewIntAnswer() Answer { // Captcha interface that should be implemented by a CAPTCHA. type Captcha interface { - // Image generates and returns a pointer to an image of CAPTCHA. + // Image generates an image of a CAPTCHA according to a passed style + // and returns a pointer to it. Image(style string) *image.Image // Answer returns a pregenerated answer. Answer() Answer @@ -37,14 +38,14 @@ type Captcha interface { // All derivatives that embed this struct only need to implement // an Image() method. type BaseCaptcha struct { - answer Answer - solved bool - expireIn time.Time + answer Answer + solved bool + expiry time.Time } func NewBaseCaptcha(expiry time.Duration) *BaseCaptcha { return &BaseCaptcha{ - expireIn: ExpiryDate(expiry), + expiry: ExpiryDate(expiry), } } @@ -52,8 +53,6 @@ func (c *BaseCaptcha) Image(style string) *image.Image { return nil } -// Answer generates an integer answer for a CAPTCHA or just returns -// an existing one. func (c *BaseCaptcha) Answer() Answer { if c.answer == "" { c.answer = NewIntAnswer() @@ -61,8 +60,6 @@ func (c *BaseCaptcha) Answer() Answer { return c.answer } -// Solve sets solved field to true if given answer is right and returns a result -// of a check. func (c *BaseCaptcha) Solve(answer Answer) bool { c.solved = c.answer == answer return c.solved @@ -73,7 +70,7 @@ func (c *BaseCaptcha) IsSolved() bool { } func (c *BaseCaptcha) Expiry() time.Time { - return c.expireIn + return c.expiry } // ExpiryDate returns a date when CAPTCHA expires. It adds a passed