-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.go
36 lines (29 loc) · 912 Bytes
/
code.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package repository
import (
"context"
"github.com/gevinzone/basic-go/live/webook/internal/repository/cache"
)
var (
ErrCodeSendTooMany = cache.ErrCodeSendTooMany
ErrCodeVerifyTooManyTimes = cache.ErrCodeVerifyTooManyTimes
)
type CodeRepository interface {
Store(ctx context.Context, biz string,
phone string, code string) error
Verify(ctx context.Context, biz, phone, inputCode string) (bool, error)
}
type CachedCodeRepository struct {
cache cache.CodeCache
}
func NewCodeRepository(c cache.CodeCache) CodeRepository {
return &CachedCodeRepository{
cache: c,
}
}
func (repo *CachedCodeRepository) Store(ctx context.Context, biz string,
phone string, code string) error {
return repo.cache.Set(ctx, biz, phone, code)
}
func (repo *CachedCodeRepository) Verify(ctx context.Context, biz, phone, inputCode string) (bool, error) {
return repo.cache.Verify(ctx, biz, phone, inputCode)
}