Documentation
¶
Overview ¶
Package captcha verifies CAPTCHA tokens with external services. Package captcha 通过外部服务验证 CAPTCHA token。
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRequired means no token was supplied. // ErrRequired 表示未提供 token。 ErrRequired = errors.New("captcha: token required") // ErrRejected means the token or its verification policy was rejected. // ErrRejected 表示 token 或其验证策略未通过。 ErrRejected = errors.New("captcha: verification rejected") // ErrMisconfigured means local parameters or provider credentials are invalid. // ErrMisconfigured 表示本地参数或服务商凭据无效。 ErrMisconfigured = errors.New("captcha: misconfigured") // ErrUnavailable 表示无法完成验证。 ErrUnavailable = errors.New("captcha: verification unavailable") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client verifies tokens concurrently without caching or automatic retries. A nil or zero Client returns ErrMisconfigured from Verify. Client 支持并发验证,不缓存结果或自动重试。 Nil 或零值 Client 的 Verify 返回 ErrMisconfigured。
func NewCap ¶
NewCap uses the full siteverify URL, including the site key, and its secret. NewCap 使用包含 site key 的完整 siteverify URL 及其 secret。
func NewRecaptchaV2 ¶
func NewRecaptchaV2(secret string, opts RecaptchaV2Options) (*Client, error)
NewRecaptchaV2 constructs a Google reCAPTCHA v2 siteverify client. NewRecaptchaV2 构造 Google reCAPTCHA v2 siteverify 客户端。
func NewRecaptchaV3 ¶
func NewRecaptchaV3(secret string, opts RecaptchaV3Options) (*Client, error)
NewRecaptchaV3 constructs a Google reCAPTCHA v3 siteverify client. Action must be non-empty; hostname and action checks use exact matching. NewRecaptchaV3 构造 Google reCAPTCHA v3 siteverify 客户端。 Action 不能为空;hostname 和 action 使用精确匹配。
func NewTurnstile ¶
func NewTurnstile(secret string, opts TurnstileOptions) (*Client, error)
NewTurnstile constructs a Cloudflare Turnstile verifier. NewTurnstile 构造 Cloudflare Turnstile 验证客户端。
func (*Client) Verify ¶
Verify consumes token and returns nil only when all verification checks pass. Errors match the package sentinels with errors.Is; cancellation also matches context.Canceled or context.DeadlineExceeded. Error text excludes credentials, tokens, raw provider responses and transport error text. Verify 消费 token,仅在全部验证通过时返回 nil。 错误可通过 errors.Is 匹配包内哨兵;取消还可匹配 context.Canceled 或 context.DeadlineExceeded。错误文本不包含凭据、token、上游原始响应或传输错误文本。
type Options ¶
type Options struct {
// HTTPClient is copied; its transport remains shared and owned by the caller.
// Nil uses http.DefaultClient. Redirects are never followed.
// HTTPClient 会被复制;transport 仍由调用方持有并共享。
// Nil 使用 http.DefaultClient。不会跟随重定向。
HTTPClient *http.Client
// Timeout bounds the entire verification. Zero defaults to five seconds.
// Timeout 限制整个验证耗时。零值默认为五秒。
Timeout time.Duration
}
Options controls verification requests. Constructors perform no network I/O. Options 控制验证请求。构造函数不进行网络访问。
type RecaptchaV2Options ¶
RecaptchaV2Options adds an exact hostname check when non-empty. RecaptchaV2Options 在 hostname 非空时执行精确匹配。
type RecaptchaV3Options ¶
type RecaptchaV3Options struct {
Options
Hostname string
Action string
// MinScore is in [0, 1]. Nil defaults to 0.5; the value is copied.
// MinScore 取值为 [0, 1]。Nil 默认为 0.5;值会被复制。
MinScore *float64
}
RecaptchaV3Options requires an action and checks the returned score. RecaptchaV3Options 要求提供 action 并检查返回的评分。
type TurnstileOptions ¶
TurnstileOptions adds exact hostname and action checks when non-empty. TurnstileOptions 在 hostname 和 action 非空时执行精确匹配。