[MSP-1388]::[v] описание для swagger
This commit is contained in:
1 parent
b4e9c9a563
commit
2e2b903463
5 files changed
+40
-12
No files matched your search
+22
-4
@@ -9,10 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type LockerService interface {
|
||||
// All(ctx context.Context) ([]domain.Locker, error)
|
||||
// Get(ctx context.Context, id int) (*domain.Locker, error)
|
||||
Lock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.Request) (domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
}
|
||||
|
||||
type Locker struct {
|
||||
@@ -20,12 +18,32 @@ type Locker struct {
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// Lock
|
||||
// @Tags locker
|
||||
// @Summary выставляем лок на строку
|
||||
// @Description `key` - строка для лока
|
||||
// @Description Возвращаем ключ для разблокировки
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.LockResponse
|
||||
// @Failure 500 {object}
|
||||
// @Router /api/isp-lock-service/lock [POST]
|
||||
func (l Locker) Lock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call ctrl.Lock")
|
||||
return l.s.Lock(ctx, req)
|
||||
}
|
||||
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (domain.LockResponse, error) {
|
||||
// UnLock
|
||||
// @Tags locker
|
||||
// @Summary снимаем лок со строки
|
||||
// @Description `key` - строка для лока
|
||||
// @Description `locKKey` - ключ для разблокировки, полученный из Lock
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.LockResponse
|
||||
// @Failure 500 {object} {}
|
||||
// @Router /api/isp-lock-service/lock [POST]
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call ctrl.UnLock")
|
||||
return l.s.UnLock(ctx, req)
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package domain
|
||||
import "time"
|
||||
|
||||
type Request struct {
|
||||
Key string
|
||||
Key string `json:"Key" valid:"required"`
|
||||
LockKey string
|
||||
TTL time.Duration
|
||||
}
|
||||
|
||||
@@ -22,6 +22,18 @@ type RC struct {
|
||||
l *log.Adapter
|
||||
}
|
||||
|
||||
func NewRCWithClient(cfg conf.Remote, l *log.Adapter, cli *goredislib.Client) (*RC, error) {
|
||||
r := RC{
|
||||
timeOut: cfg.Redis.DefaultTimeOut * time.Second,
|
||||
prefix: cfg.Redis.Prefix,
|
||||
l: l,
|
||||
}
|
||||
|
||||
r.cli = redsync.New(goredis.NewPool(cli))
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func NewRC(cfg conf.Remote, l *log.Adapter) (*RC, error) {
|
||||
r := RC{
|
||||
timeOut: cfg.Redis.DefaultTimeOut * time.Second,
|
||||
@@ -25,14 +25,14 @@ func (l Locker) Lock(ctx context.Context, req domain.Request) (*domain.LockRespo
|
||||
return &domain.LockResponse{LockKey: val}, nil
|
||||
}
|
||||
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (domain.LockResponse, error) {
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call repo.UnLock")
|
||||
_, err := l.rc.UnLock(req.Key, req.LockKey)
|
||||
if err != nil {
|
||||
l.logger.Error(ctx, err)
|
||||
return domain.LockResponse{}, err
|
||||
return &domain.LockResponse{}, err
|
||||
}
|
||||
return domain.LockResponse{}, nil
|
||||
return &domain.LockResponse{}, nil
|
||||
}
|
||||
|
||||
func NewLocker(logger log.Logger, rc *rc.RC) Locker {
|
||||
|
||||
+2
-4
@@ -9,10 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type LockerRepo interface {
|
||||
// All(ctx context.Context) ([]entity.Locker, error)
|
||||
// Get(ctx context.Context, id int) (*entity.Locker, error)
|
||||
Lock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.Request) (domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
}
|
||||
|
||||
type Locker struct {
|
||||
@@ -25,7 +23,7 @@ func (l Locker) Lock(ctx context.Context, req domain.Request) (*domain.LockRespo
|
||||
return l.repo.Lock(ctx, req)
|
||||
}
|
||||
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (domain.LockResponse, error) {
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call srv.UnLock")
|
||||
return l.repo.UnLock(ctx, req)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user