generateAnswer() function made into a private. And now being called by GetAnswer() method in Captcha.

This commit is contained in:
Alexander Andreev 2022-06-27 00:44:11 +04:00
parent 10167c4e17
commit 9ed5ad42e2
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -68,6 +68,9 @@ func (c *Captcha) Solve(answer Answer) bool {
} }
func (c *Captcha) GetAnswer() Answer { func (c *Captcha) GetAnswer() Answer {
if c.Answer == "" {
c.Answer = generateAnswer()
}
return c.Answer return c.Answer
} }
@ -79,7 +82,7 @@ func (c *Captcha) Expiry() time.Time {
return c.ExpireIn return c.ExpireIn
} }
func GenerateAnswer() Answer { func generateAnswer() Answer {
ans, _ := rand.Int(rand.Reader, big.NewInt(maxAnswer)) ans, _ := rand.Int(rand.Reader, big.NewInt(maxAnswer))
return (Answer(ans.String())) return (Answer(ans.String()))
} }