Documentation
¶
Index ¶
- Variables
- func SessionIDFromContext(ctx context.Context) string
- func WithSessionID(ctx context.Context, gen IDGenerator) context.Context
- type CaptchaResolveEngine
- type CaptchaResolver
- type CaptchaResult
- type CaptchaSession
- type EngineOption
- type HTTPDoer
- type IDFunc
- type IDGenerator
- type Option
- type Preprocessor
- type ResultReporter
- type StatsCaptchaResolver
- func (s *StatsCaptchaResolver) Report(ctx context.Context, captcha *CaptchaResult, correct bool) error
- func (s *StatsCaptchaResolver) ResolveFile(ctx context.Context, r io.Reader) (*CaptchaResult, error)
- func (s *StatsCaptchaResolver) ResolveImage(ctx context.Context, img image.Image) (*CaptchaResult, error)
- type StatsPreprocessor
- type StatsSymbolResolver
- type SymbolResolver
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrCaptchaInvalid = errors.New("captcha is invalid")
)
View Source
var (
ErrLimitExceeded = errors.New("session: retry limit exceeded")
)
Functions ¶
func SessionIDFromContext ¶
func WithSessionID ¶
func WithSessionID(ctx context.Context, gen IDGenerator) context.Context
Types ¶
type CaptchaResolveEngine ¶
type CaptchaResolveEngine struct {
// contains filtered or unexported fields
}
func NewCaptchaResolveEngine ¶
func NewCaptchaResolveEngine(opts ...Option) (*CaptchaResolveEngine, error)
NewCaptchaResolveEngine creates a new captcha resolve engine.
func (*CaptchaResolveEngine) ResolveFile ¶
func (e *CaptchaResolveEngine) ResolveFile(ctx context.Context, r io.Reader) (*CaptchaResult, error)
ResolveFile resolves the captcha from the file.
func (*CaptchaResolveEngine) ResolveImage ¶
func (e *CaptchaResolveEngine) ResolveImage(ctx context.Context, img image.Image) (*CaptchaResult, error)
ResolveImage resolves the captcha from the image.
type CaptchaResolver ¶
type CaptchaResult ¶
type CaptchaResult struct {
Captcha string `json:"captcha"`
}
type CaptchaSession ¶
type CaptchaSession struct { // Captcha is the function to fetch the captcha image, it should use // the HTTPDoer to make requests. Captcha func(_ context.Context, c HTTPDoer) (io.ReadCloser, error) // Main is the function will be invoked after the captcha is resolved. Main func(_ context.Context, c HTTPDoer, captcha string) (any, error) // Engine is the captcha resolver. Engine CaptchaResolver // IDGenerator generates a new session ID. IDGenerator IDGenerator // RetryCount is the number of retries, 0 means no retry. RetryCount int // Transport is the HTTP transport used to make requests. Transport http.RoundTripper }
type EngineOption ¶
type EngineOption struct {
// contains filtered or unexported fields
}
type IDGenerator ¶
type IDGenerator interface {
NewID() string
}
type Option ¶
type Option func(*EngineOption) error
func WithBinaryWidth ¶
func WithCaptchaLength ¶
func WithPreprocessor ¶
func WithPreprocessor(preprocessor Preprocessor) Option
func WithSymbolResolver ¶
func WithSymbolResolver(sr SymbolResolver) Option
type Preprocessor ¶
type ResultReporter ¶
type ResultReporter interface {
Report(ctx context.Context, result *CaptchaResult, correct bool) error
}
type StatsCaptchaResolver ¶
type StatsCaptchaResolver struct {
CaptchaResolver
}
func (*StatsCaptchaResolver) Report ¶
func (s *StatsCaptchaResolver) Report(ctx context.Context, captcha *CaptchaResult, correct bool) error
func (*StatsCaptchaResolver) ResolveFile ¶
func (s *StatsCaptchaResolver) ResolveFile(ctx context.Context, r io.Reader) (*CaptchaResult, error)
func (*StatsCaptchaResolver) ResolveImage ¶
func (s *StatsCaptchaResolver) ResolveImage(ctx context.Context, img image.Image) (*CaptchaResult, error)
type StatsPreprocessor ¶
type StatsPreprocessor struct {
Preprocessor
}
type StatsSymbolResolver ¶
type StatsSymbolResolver struct {
SymbolResolver
}
func (*StatsSymbolResolver) SymbolResolve ¶
Click to show internal directories.
Click to hide internal directories.