add bookstore example
This commit is contained in:
35
example/bookstore/rpc/check/internal/logic/checklogic.go
Executable file
35
example/bookstore/rpc/check/internal/logic/checklogic.go
Executable file
@@ -0,0 +1,35 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"bookstore/rpc/check/internal/svc"
|
||||
check "bookstore/rpc/check/pb"
|
||||
"context"
|
||||
|
||||
"github.com/tal-tech/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CheckLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckLogic {
|
||||
return &CheckLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CheckLogic) Check(in *check.CheckReq) (*check.CheckResp, error) {
|
||||
resp, err := l.svcCtx.Model.FindOne(in.Book)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &check.CheckResp{
|
||||
Found: true,
|
||||
Price: resp.Price,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user