engine

package
v0.0.0-...-ddb766c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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 SessionIDFromContext(ctx context.Context) string

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)

func (*CaptchaResolveEngine) ResolveFile

func (e *CaptchaResolveEngine) ResolveFile(ctx context.Context, r io.Reader) (*CaptchaResult, error)

func (*CaptchaResolveEngine) ResolveImage

func (e *CaptchaResolveEngine) ResolveImage(ctx context.Context, img image.Image) (*CaptchaResult, error)

type CaptchaResolver

type CaptchaResolver interface {
	ResolveFile(ctx context.Context, r io.Reader) (*CaptchaResult, error)
	ResolveImage(ctx context.Context, img image.Image) (*CaptchaResult, error)
}

type CaptchaResult

type CaptchaResult struct {
	Captcha string `json:"captcha"`
}

type CaptchaSession

type CaptchaSession struct {
	CaptchaURL  string
	Engine      CaptchaResolver
	IDGenerator IDGenerator
	RetryCount  int
	Transport   http.RoundTripper
}

func NewCaptchaSession

func NewCaptchaSession(captchaURL string, eng CaptchaResolver) *CaptchaSession

func (*CaptchaSession) Fetch

func (h *CaptchaSession) Fetch(ctx context.Context, fn func(c *http.Client, captcha string) error) error

type EngineOption

type EngineOption struct {
	// contains filtered or unexported fields
}

type IDGenerator

type IDGenerator interface {
	NewID() string
}

type NoopIDGen

type NoopIDGen struct{}

func (NoopIDGen) NewID

func (s NoopIDGen) NewID() string

type Option

type Option func(*EngineOption) error

func WithBinaryWidth

func WithBinaryWidth(width int) Option

func WithCaptchaLength

func WithCaptchaLength(len int) Option

func WithPreprocessor

func WithPreprocessor(preprocessor Preprocessor) Option

func WithSymbolResolver

func WithSymbolResolver(sr SymbolResolver) Option

type Preprocessor

type Preprocessor interface {
	Preprocess(ctx context.Context, img image.Image) (image.Image, error)
}

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
}

func (*StatsPreprocessor) Preprocess

func (s *StatsPreprocessor) Preprocess(ctx context.Context, img image.Image) (image.Image, error)

type StatsSymbolResolver

type StatsSymbolResolver struct {
	SymbolResolver
}

func (*StatsSymbolResolver) SymbolResolve

func (s *StatsSymbolResolver) SymbolResolve(ctx context.Context, img image.Image) (string, error)

type SymbolResolver

type SymbolResolver interface {
	SymbolResolve(ctx context.Context, img image.Image) (string, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL