Documentation
¶
Index ¶
- func InitGlobalManager(config *Config)
- type ClickCaptcha
- type ClickCaptchaData
- type Config
- type ImageCaptcha
- type ImageCaptchaData
- type Manager
- func (m *Manager) Generate(captchaType Type) (*Result, error)
- func (m *Manager) GenerateClick() (*Result, error)
- func (m *Manager) GenerateImage() (*Result, error)
- func (m *Manager) Verify(captchaType Type, id string, data interface{}) (bool, error)
- func (m *Manager) VerifyClick(id string, positions []Point) (bool, error)
- func (m *Manager) VerifyImage(id, code string) (bool, error)
- func (m *Manager) VerifyImageWithoutDelete(id, code string) (bool, error)
- func (m *Manager) VerifyWithoutDelete(captchaType Type, id string, data interface{}) (bool, error)
- type MemoryStore
- func (s *MemoryStore) Delete(id string) error
- func (s *MemoryStore) Get(id string) (interface{}, error)
- func (s *MemoryStore) Set(id string, data interface{}, expires time.Time) error
- func (s *MemoryStore) VerifyWithFunc(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
- func (s *MemoryStore) VerifyWithFuncWithoutDelete(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
- type Point
- type Result
- type Store
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClickCaptcha ¶
type ClickCaptcha struct {
// contains filtered or unexported fields
}
ClickCaptcha 点击验证码
func NewClickCaptcha ¶
func NewClickCaptcha(width, height, count, tolerance int, expiration time.Duration, store Store) *ClickCaptcha
NewClickCaptcha 创建点击验证码管理器
func (*ClickCaptcha) Generate ¶
func (cc *ClickCaptcha) Generate() (*Result, error)
Generate 生成点击验证码
func (*ClickCaptcha) Verify ¶
func (cc *ClickCaptcha) Verify(id string, userPositions []Point) (bool, error)
Verify 验证点击验证码
func (*ClickCaptcha) VerifyWithoutDelete ¶
func (cc *ClickCaptcha) VerifyWithoutDelete(id string, userPositions []Point) (bool, error)
VerifyWithoutDelete 验证点击验证码但不删除(用于预验证)
type ClickCaptchaData ¶
type ClickCaptchaData struct {
Image string `json:"image"` // 图片Base64
Positions []Point `json:"positions"` // 需要点击的位置列表
Count int `json:"count"` // 需要点击的数量
Tolerance int `json:"tolerance"` // 容差(像素)
}
ClickCaptchaData 点击验证码数据
type Config ¶
type Config struct {
// 图形验证码配置
ImageWidth int
ImageHeight int
ImageLength int
// 点击验证码配置
ClickWidth int
ClickHeight int
ClickCount int
ClickTolerance int
// 通用配置
Expiration time.Duration
Store Store
}
Config 验证码配置
type ImageCaptcha ¶
type ImageCaptcha struct {
// contains filtered or unexported fields
}
ImageCaptcha 图形验证码
func NewImageCaptcha ¶
func NewImageCaptcha(width, height, length int, expiration time.Duration, store Store) *ImageCaptcha
NewImageCaptcha 创建图形验证码管理器
func (*ImageCaptcha) Generate ¶
func (ic *ImageCaptcha) Generate() (*Result, error)
Generate 生成图形验证码
func (*ImageCaptcha) Verify ¶
func (ic *ImageCaptcha) Verify(id, code string) (bool, error)
Verify 验证图形验证码
func (*ImageCaptcha) VerifyWithoutDelete ¶
func (ic *ImageCaptcha) VerifyWithoutDelete(id, code string) (bool, error)
VerifyWithoutDelete 验证图形验证码但不删除(用于预验证)
type ImageCaptchaData ¶
type ImageCaptchaData struct {
Image string `json:"image"` // Base64编码的图片
Code string `json:"code"` // 验证码内容(仅用于测试,生产环境不应返回)
}
ImageCaptchaData 图形验证码数据
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 统一验证码管理器
var GlobalManager *Manager
GlobalManager 全局验证码管理器
func (*Manager) GenerateClick ¶
GenerateClick 生成点击验证码
func (*Manager) GenerateImage ¶
GenerateImage 生成图形验证码
func (*Manager) VerifyClick ¶
VerifyClick 验证点击验证码
func (*Manager) VerifyImage ¶
VerifyImage 验证图形验证码
func (*Manager) VerifyImageWithoutDelete ¶
VerifyImageWithoutDelete 验证图形验证码但不删除
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore 内存存储实现
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(id string) error
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(id string) (interface{}, error)
func (*MemoryStore) Set ¶
func (s *MemoryStore) Set(id string, data interface{}, expires time.Time) error
func (*MemoryStore) VerifyWithFunc ¶
func (s *MemoryStore) VerifyWithFunc(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
func (*MemoryStore) VerifyWithFuncWithoutDelete ¶
func (s *MemoryStore) VerifyWithFuncWithoutDelete(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
VerifyWithFuncWithoutDelete 验证但不删除(用于预验证)
type Result ¶
type Result struct {
ID string `json:"id"` // 验证码ID
Type Type `json:"type"` // 验证码类型
Data map[string]interface{} `json:"data"` // 验证码数据(根据类型不同而不同)
Expires time.Time `json:"expires"` // 过期时间
}
Result 验证码生成结果
type Store ¶
type Store interface {
Set(id string, data interface{}, expires time.Time) error
Get(id string) (interface{}, error)
Delete(id string) error
VerifyWithFunc(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
VerifyWithFuncWithoutDelete(id string, input interface{}, compareFunc func(stored, input interface{}) bool) (bool, error)
}
Store 验证码存储接口
Click to show internal directories.
Click to hide internal directories.