go-zero/example/bookstore/api/internal/logic/checklogic.go

41 lines
750 B
Go
Raw Normal View History

2020-09-03 23:26:04 +08:00
package logic
import (
2020-09-27 11:10:21 +08:00
"context"
2020-09-03 23:26:04 +08:00
"bookstore/api/internal/svc"
"bookstore/api/internal/types"
"bookstore/rpc/check/checker"
"github.com/tal-tech/go-zero/core/logx"
)
type CheckLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) CheckLogic {
return CheckLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CheckLogic) Check(req types.CheckReq) (*types.CheckResp, error) {
resp, err := l.svcCtx.Checker.Check(l.ctx, &checker.CheckReq{
2020-09-27 11:10:21 +08:00
Book: req.Book,
2020-09-03 23:26:04 +08:00
})
if err != nil {
logx.Error(err)
return &types.CheckResp{}, err
2020-09-03 23:26:04 +08:00
}
return &types.CheckResp{
Found: resp.Found,
Price: resp.Price,
}, nil
2020-09-27 11:10:21 +08:00
}