cache_captcha

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const StoreKeyPrefix = "owlCaptcha:"

Variables

View Source
var ErrCaptchaNotFound = errors.New("验证码不存在")

Functions

This section is empty.

Types

type CaptchaRecord

type CaptchaRecord struct {
	Type        string     `json:"type"`                  // 验证码类型
	ClickDots   []ClickDot `json:"clickDots,omitempty"`   // 点选坐标
	SlideDX     int        `json:"slideDx,omitempty"`     // 滑块X
	SlideDY     int        `json:"slideDy,omitempty"`     // 滑块Y
	RotateAngle int        `json:"rotateAngle,omitempty"` // 旋转角度
}

type CaptchaStore

type CaptchaStore interface {
	// Save 保存验证码记录
	Save(ctx context.Context, key string, record *CaptchaRecord, ttl time.Duration) error
	// Load 加载验证码记录
	Load(ctx context.Context, key string) (*CaptchaRecord, error)
	// Remove 删除验证码记录
	Remove(ctx context.Context, key string) error
	// Start 启动存储清理或初始化逻辑
	Start()
}

type ClickDot

type ClickDot struct {
	Index  int `json:"index"`  // 点序号
	X      int `json:"x"`      // X坐标
	Y      int `json:"y"`      // Y坐标
	Width  int `json:"width"`  // 宽度
	Height int `json:"height"` // 高度
}

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore(interval time.Duration) *MemoryStore

NewMemoryStore 创建内存存储实例

func (*MemoryStore) Load

func (s *MemoryStore) Load(ctx context.Context, key string) (*CaptchaRecord, error)

Load 从内存加载验证码记录

func (*MemoryStore) Remove

func (s *MemoryStore) Remove(ctx context.Context, key string) error

Remove 从内存删除验证码记录

func (*MemoryStore) Save

func (s *MemoryStore) Save(ctx context.Context, key string, record *CaptchaRecord, ttl time.Duration) error

Save 保存验证码记录到内存

func (*MemoryStore) Start

func (s *MemoryStore) Start()

Start 启动过期数据清理协程

type RedisStore

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

func NewRedisStore

func NewRedisStore(client redis.UniversalClient) *RedisStore

NewRedisStore 创建Redis存储实例

func (*RedisStore) Load

func (s *RedisStore) Load(ctx context.Context, key string) (*CaptchaRecord, error)

Load 从Redis加载验证码记录

func (*RedisStore) Remove

func (s *RedisStore) Remove(ctx context.Context, key string) error

Remove 从Redis删除验证码记录

func (*RedisStore) Save

func (s *RedisStore) Save(ctx context.Context, key string, record *CaptchaRecord, ttl time.Duration) error

Save 保存验证码记录到Redis

func (*RedisStore) Start

func (s *RedisStore) Start()

Start Redis存储无需额外启动逻辑

Source Files

  • captcha_store_interface.go
  • store_memory.go
  • store_redis.go

Jump to

Keyboard shortcuts

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