code

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CODE_REDIS_KEY_PREFIX    = "code:phone:"
	REQUEST_REDIS_KEY_PREFIX = "request:phone:"
)

Variables

View Source
var Nop = nop{}

Functions

This section is empty.

Types

type CacheCodeStore

type CacheCodeStore struct {
	CodeStore
	// contains filtered or unexported fields
}

func CreateCacheCodeStore

func CreateCacheCodeStore(config *config.CodeStoreSetting) (*CacheCodeStore, error)

func (*CacheCodeStore) CreateCode

func (s *CacheCodeStore) CreateCode(id string, scene string, code string) error

func (*CacheCodeStore) CreateRequest

func (s *CacheCodeStore) CreateRequest(id string) error

func (*CacheCodeStore) GetCode

func (s *CacheCodeStore) GetCode(id string, scene string, remove bool) (string, bool)

func (*CacheCodeStore) RemoveCode

func (s *CacheCodeStore) RemoveCode(id string, scene string)

type CodeSender

type CodeSender interface {
	SendVerificationCode(dest string, scene string, code string) error
}

type CodeStore

type CodeStore interface {
	CreateRequest(id string) error
	CreateCode(id string, scene string, code string) error
	GetCode(id string, scene string, remove bool) (string, bool)
	RemoveCode(id string, scene string)
}

func CreateRedisCodeStore

func CreateRedisCodeStore(config *config.CodeStoreSetting) (result CodeStore, err error)

type CodeValidator

type CodeValidator interface {
	GetStore() CodeStore
	GetSender() CodeSender
	GenerateCode(target CodeValidator, dest string, scene string) (string, error)
	GetVerificationCode(target CodeValidator, dest string, scene string) (string, bool)
	CheckCode(target CodeValidator, dest string, scene string, code string) bool
}

func NewValidator

func NewValidator(sender CodeSender, store CodeStore) CodeValidator

type ExpireCode

type ExpireCode struct {
	Code       string
	Expiration time.Time
}

type MemoryCodeStore

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

func CreateMemoryCodeStore

func CreateMemoryCodeStore(config *config.CodeStoreSetting) (*MemoryCodeStore, error)

func (*MemoryCodeStore) CreateCode

func (s *MemoryCodeStore) CreateCode(id string, scene string, code string) error

func (*MemoryCodeStore) CreateRequest

func (s *MemoryCodeStore) CreateRequest(id string) error

func (*MemoryCodeStore) GetCode

func (s *MemoryCodeStore) GetCode(id string, scene string, remove bool) (string, bool)

func (*MemoryCodeStore) RemoveCode

func (s *MemoryCodeStore) RemoveCode(phone string, scene string)

type RedisCodeStore

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

func (*RedisCodeStore) CreateCode

func (s *RedisCodeStore) CreateCode(id string, scene string, code string) error

func (*RedisCodeStore) CreateRequest

func (s *RedisCodeStore) CreateRequest(id string) error

func (*RedisCodeStore) GetCode

func (s *RedisCodeStore) GetCode(id string, scene string, remove bool) (string, bool)

func (*RedisCodeStore) RedisKey

func (s *RedisCodeStore) RedisKey(name string, key string, scene string) string

func (*RedisCodeStore) RemoveCode

func (s *RedisCodeStore) RemoveCode(id string, scene string)

type Validator

type Validator struct {
	Store  CodeStore
	Sender CodeSender
}

func (*Validator) CheckCode

func (v *Validator) CheckCode(target CodeValidator, dest string, scene string, code string) bool

func (*Validator) CreateRandCode

func (v *Validator) CreateRandCode() string

创建6位随机数

func (*Validator) GenerateCode

func (v *Validator) GenerateCode(target CodeValidator, dest string, scene string) (string, error)

func (*Validator) GetSender

func (v *Validator) GetSender() CodeSender

func (*Validator) GetStore

func (v *Validator) GetStore() CodeStore

func (*Validator) GetVerificationCode

func (v *Validator) GetVerificationCode(target CodeValidator, dest string, scene string) (string, bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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