diff --git a/pkg/captcha/captcha.go b/pkg/captcha/captcha.go index 52ddbd2..17ddc61 100644 --- a/pkg/captcha/captcha.go +++ b/pkg/captcha/captcha.go @@ -18,25 +18,24 @@ func NewIntAnswer() Answer { return (Answer(ans.String())) } -// Captcha interface that should be implemented by captcha. +// Captcha interface that should be implemented by a CAPTCHA. type Captcha interface { - // Image generates and returns an image of captcha. + // Image generates and returns a pointer to an image of CAPTCHA. Image(style string) *image.Image - // GetAnswer returns a pregenerated answer. + // Answer returns a pregenerated answer. Answer() Answer // Solve compares a stored answer with a passed one. - // Sets field Solved to true if they are equal. Solve(answer Answer) bool - // IsSolved returns field IsSolved. + // IsSolved returns if a CAPTCHA is solved or not. IsSolved() bool - // Expiry returns a date after what captcha will expire. + // Expiry returns a date after what CAPTCHA will expire. Expiry() time.Time } // BaseCaptcha is a base implementation of a CAPTCHA. // -// All derivatives that embed this struct only need to -// implement Image() method. +// All derivatives that embed this struct only need to implement +// an Image() method. type BaseCaptcha struct { answer Answer solved bool @@ -53,6 +52,8 @@ 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() @@ -60,6 +61,8 @@ 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,6 +76,8 @@ func (c *BaseCaptcha) Expiry() time.Time { return c.expireIn } +// ExpiryDate returns a date when CAPTCHA expires. It adds a passed +// expiry duration to a current time. func ExpiryDate(expiry time.Duration) time.Time { return time.Now().Add(expiry) }