From 18431e0001931fa3e495f8133927c3ae9d5392fc Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Wed, 17 Aug 2022 21:46:10 +0400 Subject: [PATCH] A function for generating an answer was transformed into a constructor with specified type of integer in its name. maxAnswer constant renamed to maxIntAnswer. --- pkg/captcha/captcha.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/captcha/captcha.go b/pkg/captcha/captcha.go index 411d013..2cd47cd 100644 --- a/pkg/captcha/captcha.go +++ b/pkg/captcha/captcha.go @@ -8,11 +8,16 @@ import ( ) const ( - maxAnswer = 999999 + maxIntAnswer = 999999 ) type Answer string +func NewIntAnswer() Answer { + ans, _ := rand.Int(rand.Reader, big.NewInt(maxIntAnswer)) + return (Answer(ans.String())) +} + // Captcha interface that should be implemented by captcha. type Captcha interface { // Image generates and returns an image of captcha. @@ -54,7 +59,7 @@ func (c *BaseCaptcha) Solve(answer Answer) bool { func (c *BaseCaptcha) GetAnswer() Answer { if c.Answer == "" { - c.Answer = generateAnswer() + c.Answer = NewIntAnswer() } return c.Answer } @@ -67,11 +72,6 @@ func (c *BaseCaptcha) Expiry() time.Time { return c.ExpireIn } -func generateAnswer() Answer { - ans, _ := rand.Int(rand.Reader, big.NewInt(maxAnswer)) - return (Answer(ans.String())) -} - func ExpiryDate(expiry time.Duration) time.Time { return time.Now().Add(expiry) }