fix bookstore example
This commit is contained in:
178
doc/bookstore.md
178
doc/bookstore.md
@@ -77,25 +77,25 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
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 {
|
||||||
ok bool `json:"ok"`
|
ok bool `json:"ok"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
checkReq struct {
|
checkReq struct {
|
||||||
book string `form:"book"`
|
book string `form:"book"`
|
||||||
}
|
}
|
||||||
|
|
||||||
checkResp struct {
|
checkResp struct {
|
||||||
found bool `json:"found"`
|
found bool `json:"found"`
|
||||||
price int `json:"price"`
|
price int64 `json:"price"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
service bookstore-api {
|
service bookstore-api {
|
||||||
@@ -270,8 +270,8 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
Add rpcx.RpcClientConf // 手动代码
|
Add rpcx.RpcClientConf // 手动代码
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -279,15 +279,15 @@
|
|||||||
|
|
||||||
```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)), // 手动代码
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -297,19 +297,19 @@
|
|||||||
|
|
||||||
```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,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.AddResp{
|
return &types.AddResp{
|
||||||
Ok: resp.Ok,
|
Ok: resp.Ok,
|
||||||
}, nil
|
}, nil
|
||||||
// 手动代码结束
|
// 手动代码结束
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -404,9 +404,9 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
Add rpcx.RpcClientConf // 手动代码
|
Add rpcx.RpcClientConf // 手动代码
|
||||||
Check rpcx.RpcClientConf // 手动代码
|
Check rpcx.RpcClientConf // 手动代码
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -414,17 +414,17 @@
|
|||||||
|
|
||||||
```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)), // 手动代码
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -434,19 +434,19 @@
|
|||||||
|
|
||||||
```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 {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.CheckResp{
|
return &types.CheckResp{
|
||||||
Found: resp.Found,
|
Found: resp.Found,
|
||||||
Price: resp.Price,
|
Price: resp.Price,
|
||||||
}, nil
|
}, nil
|
||||||
// 手动代码结束
|
// 手动代码结束
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -511,10 +511,10 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rpcx.RpcServerConf
|
rpcx.RpcServerConf
|
||||||
DataSource string // 手动代码
|
DataSource string // 手动代码
|
||||||
Table string // 手动代码
|
Table string // 手动代码
|
||||||
Cache cache.CacheConf // 手动代码
|
Cache cache.CacheConf // 手动代码
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -524,15 +524,15 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
c config.Config
|
c config.Config
|
||||||
Model *model.BookModel // 手动代码
|
Model *model.BookModel // 手动代码
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
c: c,
|
c: c,
|
||||||
Model: model.NewBookModel(sqlx.NewMysql(c.DataSource), c.Cache, c.Table), // 手动代码
|
Model: model.NewBookModel(sqlx.NewMysql(c.DataSource), c.Cache, c.Table), // 手动代码
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -540,19 +540,19 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
func (l *AddLogic) Add(in *add.AddReq) (*add.AddResp, error) {
|
func (l *AddLogic) Add(in *add.AddReq) (*add.AddResp, error) {
|
||||||
// 手动代码开始
|
// 手动代码开始
|
||||||
_, err := l.svcCtx.Model.Insert(model.Book{
|
_, err := l.svcCtx.Model.Insert(model.Book{
|
||||||
Book: in.Book,
|
Book: in.Book,
|
||||||
Price: in.Price,
|
Price: in.Price,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &add.AddResp{
|
return &add.AddResp{
|
||||||
Ok: true,
|
Ok: true,
|
||||||
}, nil
|
}, nil
|
||||||
// 手动代码结束
|
// 手动代码结束
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -560,17 +560,17 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
func (l *CheckLogic) Check(in *check.CheckReq) (*check.CheckResp, error) {
|
func (l *CheckLogic) Check(in *check.CheckReq) (*check.CheckResp, error) {
|
||||||
// 手动代码开始
|
// 手动代码开始
|
||||||
resp, err := l.svcCtx.Model.FindOne(in.Book)
|
resp, err := l.svcCtx.Model.FindOne(in.Book)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &check.CheckResp{
|
return &check.CheckResp{
|
||||||
Found: true,
|
Found: true,
|
||||||
Price: resp.Price,
|
Price: resp.Price,
|
||||||
}, nil
|
}, nil
|
||||||
// 手动代码结束
|
// 手动代码结束
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user