vcode

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 7 Imported by: 0

README

vcode

验证码缓存与验证的通用模块,用于手机验证码和邮件验证码。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSendTooFreq          = status.Error(codes.ResourceExhausted, "send.code.freq.limit")
	ErrVerifyCodeRetryLimit = status.Error(codes.ResourceExhausted, "verify.code.retry.limit")
	ErrSendCountLimit       = status.Error(codes.ResourceExhausted, "send.code.count.limit")

	ErrVerifyCodeNotExist     = status.Error(codes.NotFound, "verify.code.not.exist")
	ErrVerifyCodeTimeout      = status.Error(codes.DeadlineExceeded, "verify.code.timeout")
	ErrVerifyCodeNotMatch     = status.Error(codes.Unauthenticated, "verify.code.not.match")
	ErrVerifyCodeHashNotMatch = status.Error(codes.FailedPrecondition, "verify.hash.code.not.match")
)

Functions

This section is empty.

Types

type CacheModule added in v0.6.4

type CacheModule interface {
	Get(key interface{}) (v interface{}, ok bool)
	Peek(key interface{}) (v interface{}, ok bool)
	Set(key interface{}, value interface{})
}

func NewSimpleCache

func NewSimpleCache(c int64) CacheModule

type Config

type Config struct {
	// LRU cache size.
	CacheSize int64 `json:"cache_size" toml:"cache_size"`
	// Mock mode, the verification code is the last `CodeLen` digits of the mobile phone.
	Mock bool `json:"mock" toml:"mock"`
	// Random code length.
	CodeLen int `json:"code_len" toml:"code_len"`
	// Code TTL.
	TTL tex.Duration `json:"ttl" toml:"ttl"`
	// Minimum interval for sending captcha.
	MinInterval tex.Duration `json:"min_interval" toml:"min_interval"`
	// Captcha count cycle.
	CounterDuration tex.Duration `json:"counter_duration" toml:"counter_duration"`
	// Verification code count upper limit.
	MaxCount int `json:"max_count" toml:"max_count"`
	// Upper limit of verification times of captcha.
	MaxVerifyCount int `json:"max_verify_count" toml:"max_verify_count"`
}

type VCLogic

type VCLogic interface {
	SendSMSCode(areaCode, phone string) (string, error)
	VerifySMSCode(areaCode, phone, code, hash string) error
}

func NewSimpleLogic

func NewSimpleLogic(config *Config, sms smsModule, cacheM CacheModule) VCLogic

Jump to

Keyboard shortcuts

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