Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCodeSendTooMany = errors.New("发送验证码太频繁") ErrCodeVerifyTooManyTimes = errors.New("验证次数太多") ErrUnknownForCode = errors.New("我也不知发生什么了,反正是跟 code 有关") )
View Source
var ErrKeyNotExist = redis.Nil
Functions ¶
This section is empty.
Types ¶
type CodeCache ¶
type CodeCache interface { Set(ctx context.Context, biz, phone, code string) error Verify(ctx context.Context, biz, phone, inputCode string) (bool, error) }
func NewCodeCache ¶
func NewCodeCache(client redis.Cmdable) CodeCache
func NewLocalCodeCache ¶
func NewLocalCodeCache() CodeCache
type LocalCodeCache ¶
type LocalCodeCache struct {
// contains filtered or unexported fields
}
type RedisCodeCache ¶
type RedisCodeCache struct {
// contains filtered or unexported fields
}
func NewCodeCacheGoBestPractice ¶
func NewCodeCacheGoBestPractice(client redis.Cmdable) *RedisCodeCache
NewCodeCacheGoBestPractice Go 的最佳实践是返回具体类型
type RedisUserCache ¶
type RedisUserCache struct {
// contains filtered or unexported fields
}
type UserCache ¶
type UserCache interface { Get(ctx context.Context, id int64) (domain.User, error) Set(ctx context.Context, u domain.User) error }
func NewUserCache ¶
func NewUserCache(client redis.Cmdable) UserCache
NewUserCache A 用到了 B,B 一定是接口 => 这个是保证面向接口 A 用到了 B,B 一定是 A 的字段 => 规避包变量、包方法,都非常缺乏扩展性 A 用到了 B,A 绝对不初始化 B,而是外面注入 => 保持依赖注入(DI, Dependency Injection)和依赖反转(IOC) expiration 1s, 1m
func NewUserCacheV1 ¶
Click to show internal directories.
Click to hide internal directories.