From 10167c4e1727e09f93a167e252f361bbc05abfc5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 27 Jun 2022 00:43:12 +0400 Subject: [PATCH] Added comments for ICaptcha interface. --- pkg/captcha/captcha.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/captcha/captcha.go b/pkg/captcha/captcha.go index 2b12b45..8fce4fc 100644 --- a/pkg/captcha/captcha.go +++ b/pkg/captcha/captcha.go @@ -16,15 +16,33 @@ var errorNotFound = errors.New("captcha not found") type Answer string +// ICaptcha interface that should be implemented by captcha. type ICaptcha interface { + // generateImage is used to create a captcha image. generateImage() *image.Image + // GetImage() returns an image of captcha. Calls + // generateImage() method if image doesn't exist. GetImage() *image.Image + // GetAnswer returns a pregenerated answer. GetAnswer() 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() bool + // Expiry returns a date after what captcha will expire. Expiry() time.Time } +// Captcha is a base implementation of a CAPTCHA. +// +// All derivatives that embed this struct only need to +// implement GetImage() and generateImage() methods. +// And GetImage() could simply be copied. +// +// You need to do that because in Go there is no inheritance, +// and if you won't do that, calling a base GetImage +// method will call an empty base generateImage() method. type Captcha struct { Image image.Image Answer Answer