MSP-4153 add GetLimit for daily_limiter
This commit is contained in:
1 parent
acd2c86998
commit
a803438492
5 files changed
+46
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
type dailyLimiterRepo interface {
|
||||
Increment(ctx context.Context, key string) (uint64, error)
|
||||
Set(ctx context.Context, key string, dailyLimit uint64) error
|
||||
GetLimit(ctx context.Context, key string) (uint64, error)
|
||||
}
|
||||
|
||||
type dailyLimiter struct {
|
||||
@@ -36,6 +37,15 @@ func (s dailyLimiter) Set(ctx context.Context, req domain.SetRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s dailyLimiter) GetLimit(ctx context.Context, req domain.GetRequest) (*domain.GetResponse, error) {
|
||||
v, err := s.repo.GetLimit(ctx, s.makeKey(req.Key, req.Today))
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "repo get")
|
||||
}
|
||||
|
||||
return &domain.GetResponse{Value: v}, nil
|
||||
}
|
||||
|
||||
func (s dailyLimiter) makeKey(key string, today time.Time) string {
|
||||
return fmt.Sprintf("%s:%s", key, today.Format(time.DateOnly))
|
||||
}
|
||||
Reference in new issue
Block a user