update bookstore example for generation prototype

This commit is contained in:
kevin
2020-10-31 11:42:44 +08:00
parent 7b9ed7a313
commit b144a2335c
20 changed files with 513 additions and 118 deletions

View File

@@ -8,9 +8,9 @@ import (
"fmt"
"bookstore/rpc/add/internal/config"
add "bookstore/rpc/add/internal/pb"
"bookstore/rpc/add/internal/server"
"bookstore/rpc/add/internal/svc"
add "bookstore/rpc/add/pb"
"github.com/tal-tech/go-zero/core/conf"
"github.com/tal-tech/go-zero/core/logx"

View File

@@ -8,13 +8,15 @@ package adder
import (
"context"
add "bookstore/rpc/add/pb"
add "bookstore/rpc/add/internal/pb"
"github.com/tal-tech/go-zero/core/jsonx"
"github.com/tal-tech/go-zero/zrpc"
)
type (
AddReq = add.AddReq
AddResp = add.AddResp
Adder interface {
Add(ctx context.Context, in *AddReq) (*AddResp, error)
}
@@ -31,33 +33,6 @@ func NewAdder(cli zrpc.Client) Adder {
}
func (m *defaultAdder) Add(ctx context.Context, in *AddReq) (*AddResp, error) {
var request add.AddReq
bts, err := jsonx.Marshal(in)
if err != nil {
return nil, errJsonConvert
}
err = jsonx.Unmarshal(bts, &request)
if err != nil {
return nil, errJsonConvert
}
client := add.NewAdderClient(m.cli.Conn())
resp, err := client.Add(ctx, &request)
if err != nil {
return nil, err
}
var ret AddResp
bts, err = jsonx.Marshal(resp)
if err != nil {
return nil, errJsonConvert
}
err = jsonx.Unmarshal(bts, &ret)
if err != nil {
return nil, errJsonConvert
}
return &ret, nil
adder := add.NewAdderClient(m.cli.Conn())
return adder.Add(ctx, in)
}

View File

@@ -1,19 +0,0 @@
// Code generated by goctl. DO NOT EDIT!
// Source: add.proto
package adder
import "errors"
var errJsonConvert = errors.New("json convert error")
type (
AddReq struct {
Book string `json:"book,omitempty"`
Price int64 `json:"price,omitempty"`
}
AddResp struct {
Ok bool `json:"ok,omitempty"`
}
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
add "bookstore/rpc/add/internal/pb"
"bookstore/rpc/add/internal/svc"
add "bookstore/rpc/add/pb"
"bookstore/rpc/model"
"github.com/tal-tech/go-zero/core/logx"

View File

@@ -14,13 +14,13 @@ It has these top-level messages:
*/
package add
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
"fmt"
"math"
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -7,8 +7,8 @@ import (
"context"
"bookstore/rpc/add/internal/logic"
add "bookstore/rpc/add/internal/pb"
"bookstore/rpc/add/internal/svc"
add "bookstore/rpc/add/pb"
)
type AdderServer struct {

View File

@@ -8,9 +8,9 @@ import (
"fmt"
"bookstore/rpc/check/internal/config"
check "bookstore/rpc/check/internal/pb"
"bookstore/rpc/check/internal/server"
"bookstore/rpc/check/internal/svc"
check "bookstore/rpc/check/pb"
"github.com/tal-tech/go-zero/core/conf"
"github.com/tal-tech/go-zero/core/logx"

View File

@@ -8,13 +8,15 @@ package checker
import (
"context"
check "bookstore/rpc/check/pb"
check "bookstore/rpc/check/internal/pb"
"github.com/tal-tech/go-zero/core/jsonx"
"github.com/tal-tech/go-zero/zrpc"
)
type (
CheckReq = check.CheckReq
CheckResp = check.CheckResp
Checker interface {
Check(ctx context.Context, in *CheckReq) (*CheckResp, error)
}
@@ -31,33 +33,6 @@ func NewChecker(cli zrpc.Client) Checker {
}
func (m *defaultChecker) Check(ctx context.Context, in *CheckReq) (*CheckResp, error) {
var request check.CheckReq
bts, err := jsonx.Marshal(in)
if err != nil {
return nil, errJsonConvert
}
err = jsonx.Unmarshal(bts, &request)
if err != nil {
return nil, errJsonConvert
}
client := check.NewCheckerClient(m.cli.Conn())
resp, err := client.Check(ctx, &request)
if err != nil {
return nil, err
}
var ret CheckResp
bts, err = jsonx.Marshal(resp)
if err != nil {
return nil, errJsonConvert
}
err = jsonx.Unmarshal(bts, &ret)
if err != nil {
return nil, errJsonConvert
}
return &ret, nil
checker := check.NewCheckerClient(m.cli.Conn())
return checker.Check(ctx, in)
}

View File

@@ -1,19 +0,0 @@
// Code generated by goctl. DO NOT EDIT!
// Source: check.proto
package checker
import "errors"
var errJsonConvert = errors.New("json convert error")
type (
CheckReq struct {
Book string `json:"book,omitempty"`
}
CheckResp struct {
Found bool `json:"found,omitempty"`
Price int64 `json:"price,omitempty"`
}
)

View File

@@ -3,8 +3,8 @@ package logic
import (
"context"
check "bookstore/rpc/check/internal/pb"
"bookstore/rpc/check/internal/svc"
check "bookstore/rpc/check/pb"
"github.com/tal-tech/go-zero/core/logx"
)

View File

@@ -14,13 +14,13 @@ It has these top-level messages:
*/
package check
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
"fmt"
"math"
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -7,8 +7,8 @@ import (
"context"
"bookstore/rpc/check/internal/logic"
check "bookstore/rpc/check/internal/pb"
"bookstore/rpc/check/internal/svc"
check "bookstore/rpc/check/pb"
)
type CheckerServer struct {