From 2c22ff00e649411db18ab036f42816c4fb41cf0c Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 29 Aug 2022 00:02:58 +0400 Subject: [PATCH] Added comments for BaseCaptcha. Fixed comments for the Captcha interface. --- pkg/captcha/captcha.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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) }