fix bookstore example

master
kevin 4 years ago
parent 81a9ada2d9
commit a74d73fb2e

@ -79,7 +79,7 @@
type ( type (
addReq struct { addReq struct {
book string `form:"book"` book string `form:"book"`
price int `form:"price"` price int64 `form:"price"`
} }
addResp struct { addResp struct {
@ -94,7 +94,7 @@
checkResp struct { checkResp struct {
found bool `json:"found"` found bool `json:"found"`
price int `json:"price"` price int64 `json:"price"`
} }
) )
@ -280,13 +280,13 @@
```go ```go
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
Adder rpcx.Client // 手动代码 Adder adder.Adder // 手动代码
} }
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,
Adder: rpcx.MustNewClient(c.Add), // 手动代码 Adder: adder.NewAdder(rpcx.MustNewClient(c.Add)), // 手动代码
} }
} }
``` ```
@ -298,7 +298,7 @@
```go ```go
func (l *AddLogic) Add(req types.AddReq) (*types.AddResp, error) { func (l *AddLogic) Add(req types.AddReq) (*types.AddResp, error) {
// 手动代码开始 // 手动代码开始
resp, err := adder.NewAdder(l.svcCtx.Adder).Add(l.ctx, &adder.AddReq{ resp, err := l.svcCtx.Adder.Add(l.ctx, &adder.AddReq{
Book: req.Book, Book: req.Book,
Price: req.Price, Price: req.Price,
}) })
@ -415,15 +415,15 @@
```go ```go
type ServiceContext struct { type ServiceContext struct {
Config config.Config Config config.Config
Adder rpcx.Client // 手动代码 Adder adder.Adder // 手动代码
Checker rpcx.Client // 手动代码 Checker checker.Checker // 手动代码
} }
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{ return &ServiceContext{
Config: c, Config: c,
Adder: rpcx.MustNewClient(c.Add), // 手动代码 Adder: adder.NewAdder(rpcx.MustNewClient(c.Add)), // 手动代码
Checker: rpcx.MustNewClient(c.Check), // 手动代码 Checker: checker.NewChecker(rpcx.MustNewClient(c.Check)), // 手动代码
} }
} }
``` ```
@ -435,7 +435,7 @@
```go ```go
func (l *CheckLogic) Check(req types.CheckReq) (*types.CheckResp, error) { func (l *CheckLogic) Check(req types.CheckReq) (*types.CheckResp, error) {
// 手动代码开始 // 手动代码开始
resp, err := checker.NewChecker(l.svcCtx.Checker).Check(l.ctx, &checker.CheckReq{ resp, err := l.svcCtx.Checker.Check(l.ctx, &checker.CheckReq{
Book: req.Book, Book: req.Book,
}) })
if err != nil { if err != nil {

Loading…
Cancel
Save