Documentation ¶
Index ¶
- Constants
- Variables
- type CodeParam
- type CodeParamOption
- type DecrArgs
- type IncrArgs
- type LimitVerified
- func (v *LimitVerified[P, S]) Decr(ctx context.Context, target string) error
- func (v *LimitVerified[P, S]) Incr(ctx context.Context, target string) error
- func (v *LimitVerified[P, S]) Name() string
- func (v *LimitVerified[P, S]) SendCode(ctx context.Context, c CodeParam, opts ...CodeParamOption) error
- func (v *LimitVerified[P, S]) VerifyCode(ctx context.Context, c CodeParam) error
- type LimitVerifiedProvider
- type Option
- func WithCodeAvailWindowSecond(sec int) Option
- func WithCodeMaxErrorQuota(cnt int) Option
- func WithCodeMaxSendPerDay(cnt int) Option
- func WithCodeResendIntervalSecond(sec int) Option
- func WithKeyExpires(expires time.Duration) Option
- func WithKeyPrefix(k string) Option
- func WithMaxSendPerDay(cnt int) Option
- type OptionSetter
- type RollbackArgs
- type Storage
- type StoreArgs
- type VerifyArgs
Constants ¶
const DefaultKind = "default"
Variables ¶
var ( // ErrUnknownCode is an error that represents unknown status code. ErrUnknownCode = errors.New("limit: unknown status code") ErrMaxSendPerDay = errors.New("limit: reach the maximum send times") ErrResendTooFrequently = errors.New("limit: resend too frequently") ErrCodeRequiredOrExpired = errors.New("limit: code is required or expired") ErrCodeMaxErrorQuota = errors.New("limit: over the maximum error quota") ErrCodeVerification = errors.New("limit: code verified failed") )
error defined for verified
Functions ¶
This section is empty.
Types ¶
type CodeParamOption ¶
type CodeParamOption func(*CodeParam)
CodeParamOption LimitVerified code 选项
func WithAvailWindowSecond ¶
func WithAvailWindowSecond(sec int) CodeParamOption
WithAvailWindowSecond 验证码有效窗口时间, 覆盖默认值, 单位: 秒
func WithMaxErrorQuota ¶
func WithMaxErrorQuota(cnt int) CodeParamOption
WithMaxErrorQuota 验证码最大验证失败次数, 覆盖默认值
func WithResendIntervalSecond ¶
func WithResendIntervalSecond(sec int) CodeParamOption
WithResendIntervalSecond 重发验证码间隔时间, 覆盖默认值, 单位: 秒
type LimitVerified ¶
type LimitVerified[P LimitVerifiedProvider, S Storage] struct { // contains filtered or unexported fields }
LimitVerified limit verified code
func NewLimitVerified ¶
func NewLimitVerified[P LimitVerifiedProvider, S Storage](p P, store S, opts ...Option) *LimitVerified[P, S]
NewLimitVerified new a limit verified
func (*LimitVerified[P, S]) Decr ¶
func (v *LimitVerified[P, S]) Decr(ctx context.Context, target string) error
Decr send cnt.
func (*LimitVerified[P, S]) Incr ¶
func (v *LimitVerified[P, S]) Incr(ctx context.Context, target string) error
Incr send cnt.
func (*LimitVerified[P, S]) Name ¶
func (v *LimitVerified[P, S]) Name() string
Name the provider name
func (*LimitVerified[P, S]) SendCode ¶
func (v *LimitVerified[P, S]) SendCode(ctx context.Context, c CodeParam, opts ...CodeParamOption) error
SendCode send code and store.
func (*LimitVerified[P, S]) VerifyCode ¶
func (v *LimitVerified[P, S]) VerifyCode(ctx context.Context, c CodeParam) error
VerifyCode verify code from cache.
type LimitVerifiedProvider ¶
LimitVerifiedProvider the provider
type Option ¶
type Option func(OptionSetter)
Option LimitVerified 选项
func WithCodeAvailWindowSecond ¶
WithCodeAvailWindowSecond 验证码有效窗口时间, 默认180, 单位: 秒
func WithCodeMaxErrorQuota ¶
WithCodeMaxErrorQuota 验证码最大验证失败次数, 默认: 3
func WithCodeMaxSendPerDay ¶
WithMaxSendPerDay 验证码限制一天最大发送次数(验证码全局), 默认: 10
func WithCodeResendIntervalSecond ¶
WithCodeResendIntervalSecond 验证码重发间隔时间, 默认60, 单位: 秒
func WithKeyExpires ¶
WithKeyExpires redis存验证码key的过期时间, 默认 24小时
func WithKeyPrefix ¶
WithKeyPrefix redis存验证码key的前缀, 默认 limit:verified:
func WithMaxSendPerDay ¶
WithMaxSendPerDay 限制一天最大发送次数(全局), 默认: 10
type OptionSetter ¶ added in v0.1.0
type OptionSetter interface {
// contains filtered or unexported methods
}
OptionSetter option setter
type RollbackArgs ¶
type Storage ¶
type Storage interface { // Store code Store(context.Context, *StoreArgs) error // Rollback when store success but send code failed. Rollback(context.Context, *RollbackArgs) error // Verify code Verify(context.Context, *VerifyArgs) error // Incr send cnt. Incr(context.Context, *IncrArgs) error // Decr send cnt. Decr(context.Context, *DecrArgs) error }
type StoreArgs ¶
type StoreArgs struct { KeyPrefix string // 存验证码key的前缀 Kind string // CodeParam.Kind Target string // CodeParam.Target KeyExpires time.Duration // 存验证码key的过期时间 MaxSendPerDay int // 限制一天最大发送次数(全局) Code string // CodeParam.Code CodeMaxSendPerDay int // 验证码限制一天最大发送次数(验证码全局) CodeMaxErrorQuota int // 验证码最大验证失败次数 CodeAvailWindowSecond int // 验证码有效窗口时间 CodeResendIntervalSecond int // 验证码重发间隔时间, NowSecond string // 当前时间, 秒 }
StoreArgs store arguments