Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultExpire 默认过期时间(2个小时) DefaultExpire = time.Hour * 2 // DefaultCodeLen 默认验证码的长度 DefaultCodeLen = 6 // DefaultGCInterval 默认验证信息的GC间隔 DefaultGCInterval = time.Second * 60 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodeValidate ¶
type CodeValidate struct {
// contains filtered or unexported fields
}
CodeValidate 提供验证码验证
func NewCodeValidate ¶
func NewCodeValidate(store Store, cfg ...Config) *CodeValidate
NewCodeValidate 创建CodeValidate的实例 store 验证信息存储方式 cfg 配置参数(可使用默认参数)
type DataItem ¶
type DataItem struct {
ID int64 // 唯一标识
Email string // 邮箱
Code string // 验证码
CreateTime time.Time // 存储时间
Expire time.Duration // 过期的持续时间
}
DataItem 存储验证信息的数据项
type MemoryStore ¶
MemoryStore 提供内存存储
func (*MemoryStore) TakeByEmailAndCode ¶
func (this *MemoryStore) TakeByEmailAndCode(email, code string) (*DataItem, error)
Take Take item by email and code
type Store ¶
type Store interface {
// Put 将元素放入存储,返回存储的ID
// 如果存储发生异常,则返回错误
Put(item DataItem) (int64, error)
// TakeByID 根据ID取出一个元素,返回取出的元素
// 如果取出元素发生异常,则返回错误
TakeByID(id int64) (*DataItem, error)
// TakeByEmailAndCode 根据验证码和验证码取出一个元素,返回取出的元素
// 如果取出元素发生异常,则返回错误
TakeByEmailAndCode(email, code string) (*DataItem, error)
}
Store 提供线程安全的验证信息存储接口,支持自动GC过期的元素
func NewMemoryStore ¶
NewMemoryStore 创建基于内存存储的存储实例
type TokenValidate ¶
type TokenValidate struct {
// contains filtered or unexported fields
}
TokenValidate 提供令牌验证
func NewTokenValidate ¶
func NewTokenValidate(store Store, cfg ...Config) *TokenValidate
NewTokenValidate 创建TokenValidate的实例 store 验证信息存储方式 cfg 配置参数(可使用默认参数)
Click to show internal directories.
Click to hide internal directories.