Documentation
¶
Index ¶
- Constants
- Variables
- func CheckCaptcha(id [64]byte, solution []byte) error
- func Close() error
- func DecodeID(s string) (id [64]byte, err error)
- func ExtractCaptcha(r io.Reader) (id [64]byte, solution []byte, err error)
- func ExtractID(r *http.Request) (id [64]byte, err error)
- func ExtractSolution(r *http.Request) (solution []byte, err error)
- func Open() error
- func ServeStatus(w http.ResponseWriter, r *http.Request) (err error)
- type DataSource
- type Error
- type Options
- type Rating
- type Service
- func (s *Service) NewCaptcha(w io.Writer, colour, background string) (id [64]byte, err error)
- func (s *Service) Router() *httprouter.Router
- func (s *Service) ServeCheckCaptcha(w http.ResponseWriter, r *http.Request) (err error)
- func (s *Service) ServeNewCaptcha(w http.ResponseWriter, r *http.Request) (err error)
Constants ¶
const ( // Keys used as names for input elements in captcha form HTML IDKey = common.IDKey ColourKey = common.ColourKey BackgroundKey = common.BackgroundKey )
const ( Gelbooru = common.Gelbooru Danbooru = common.Danbooru )
Variables ¶
var ( // Signifies the client had solved the captcha incorrectly ErrInvalidSolution = Error{errors.New("invalid captcha solution")} // Captcha ID is of invalid format ErrInvalidID = Error{errors.New("invalid captcha id")} )
var ( // No faces detected in downloaded image ErrNoFace = Error{fmt.Errorf("no faces detected")} )
Functions ¶
func CheckCaptcha ¶
Check a captcha solution for validity. solution: slice of selected image numbers
func ExtractCaptcha ¶
Extract captcha from GZipped HTML body and return together with its solution
func ExtractSolution ¶
Extact captcha ID and solution from request
func ServeStatus ¶
func ServeStatus(w http.ResponseWriter, r *http.Request) (err error)
Serve captcha solved status. The captcha is deleted on a successful check to prevent replayagain attacks.
Types ¶
type DataSource ¶
type DataSource = common.DataSource
Source of image database to use for captcha image generation
type Options ¶
type Options struct { // Silence non-error log outputs Quiet bool // Allow images with varying explicitness. Defaults to only Safe. Explicitness []Rating // Tags to source for captcha solutions. One tag is randomly chosen for each // generated captcha. Required to contain at least 3 tags. // // Note that you can only include tags that are discernable from the // character's face, such as who the character is (example: "cirno") or a // facial feature of the character (example: "smug"). Tags []string }
Options passed on Service creation
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Encapsulates a configured captcha-generation and verification service
func NewService ¶
Create new captcha-generation and verification service
func (*Service) NewCaptcha ¶
Creates a new captcha, writes its HTML contents to w and returns captcha ID.
Depending on what type w is, you might want to buffer the output with bufio.NewWriter.
func (*Service) Router ¶
func (s *Service) Router() *httprouter.Router
Creates a routed handler for serving the API. The router implements http.Handler.
func (*Service) ServeCheckCaptcha ¶
Serve POST requests for captcha solution validation
func (*Service) ServeNewCaptcha ¶
Generate new captcha and serve its HTML form