Help us shape the future of Go! Take the 2026 Go Developer Survey

captcha

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Application scenarios: - Multi-instance shared captcha store backed by Redis. - Graceful automatic fallback to in-memory store when Redis is unavailable. - High-availability verification with timeout control.

适用场景: - 基于 Redis 的多实例共享验证码存储。 - Redis 不可用时自动优雅降级为单机内存存储。 - 带超时控制的高可用验证码校验。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*RedisCaptchaStore)

Option configures RedisCaptchaStore options.

func WithExpiration

func WithExpiration(expiration time.Duration) Option

WithExpiration configures the captcha TTL.

func WithFallback

func WithFallback(fallback base64Captcha.Store) Option

WithFallback configures the fallback store when Redis is unavailable or errors.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix configures the Redis key prefix for captcha entries.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout configures the timeout for Redis operations.

type RedisCaptchaStore

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

RedisCaptchaStore implements base64Captcha.Store and securitycontract.CaptchaStore backed by Redis, with automatic graceful fallback to an in-memory store.

func NewRedisCaptchaStore

func NewRedisCaptchaStore(redis datacontract.Redis, opts ...Option) *RedisCaptchaStore

NewRedisCaptchaStore creates a captcha store instance. If redis is nil, it automatically delegates to base64Captcha.DefaultMemStore.

func (*RedisCaptchaStore) Get

func (s *RedisCaptchaStore) Get(id string, clear bool) string

Get retrieves the captcha value by id, optionally clearing it.

func (*RedisCaptchaStore) Set

func (s *RedisCaptchaStore) Set(id string, value string) error

Set stores the captcha value with expiration.

func (*RedisCaptchaStore) Verify

func (s *RedisCaptchaStore) Verify(id, answer string, clear bool) bool

Verify verifies the given captcha answer, optionally clearing the entry.

Jump to

Keyboard shortcuts

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