captcha

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCaptcha = errors.New("invalid captcha")
View Source
var ErrMissingCaptcha = errors.New("missing captcha token")

Functions

This section is empty.

Types

type Config

type Config struct {
	ClientKey string
	ServerKey string
}

Config holds optional SmartCaptcha keys.

func Load

func Load() (Config, error)

Load reads YANDEX_CAPTCHA_* keys. Both empty is OK; only one set is an error.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether both keys are set.

type NopVerifier

type NopVerifier struct{}

NopVerifier always succeeds and reports disabled.

func NewNopVerifier

func NewNopVerifier() *NopVerifier

NewNopVerifier returns a no-op verifier.

func (*NopVerifier) Enabled

func (n *NopVerifier) Enabled() bool

Enabled always returns false.

func (*NopVerifier) Verify

Verify always succeeds.

type Verifier

type Verifier interface {
	Enabled() bool
	Verify(ctx context.Context, token, clientIP string) error
}

Verifier checks a Yandex SmartCaptcha token.

func NewFromConfig

func NewFromConfig(cfg Config) Verifier

NewFromConfig returns a nop verifier when captcha is disabled.

type YandexVerifier

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

YandexVerifier validates tokens against Yandex SmartCaptcha.

func NewYandexVerifier

func NewYandexVerifier(serverKey string) *YandexVerifier

NewYandexVerifier builds a verifier with a 5s HTTP timeout.

func (*YandexVerifier) Enabled

func (y *YandexVerifier) Enabled() bool

Enabled reports whether a server key is configured.

func (*YandexVerifier) SetValidateURL

func (y *YandexVerifier) SetValidateURL(u string)

SetValidateURL overrides the validation endpoint (tests).

func (*YandexVerifier) Verify

func (y *YandexVerifier) Verify(ctx context.Context, token, clientIP string) error

Verify posts the token to Yandex SmartCaptcha.

Jump to

Keyboard shortcuts

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