From 9ed5ad42e27823942f8cdb7914f2c095adafb97d Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 27 Jun 2022 00:44:11 +0400 Subject: [PATCH] generateAnswer() function made into a private. And now being called by GetAnswer() method in Captcha. --- pkg/captcha/captcha.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/captcha/captcha.go b/pkg/captcha/captcha.go index 8fce4fc..141fd6d 100644 --- a/pkg/captcha/captcha.go +++ b/pkg/captcha/captcha.go @@ -68,6 +68,9 @@ func (c *Captcha) Solve(answer Answer) bool { } func (c *Captcha) GetAnswer() Answer { + if c.Answer == "" { + c.Answer = generateAnswer() + } return c.Answer } @@ -79,7 +82,7 @@ func (c *Captcha) Expiry() time.Time { return c.ExpireIn } -func GenerateAnswer() Answer { +func generateAnswer() Answer { ans, _ := rand.Int(rand.Reader, big.NewInt(maxAnswer)) return (Answer(ans.String())) }