You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
4 years ago
|
// Code generated by goctl. DO NOT EDIT!
|
||
|
// Source: add.proto
|
||
|
|
||
|
//go:generate mockgen -destination ./adder_mock.go -package adder -source $GOFILE
|
||
|
|
||
|
package adder
|
||
|
|
||
|
import (
|
||
|
add "bookstore/rpc/add/pb"
|
||
|
"context"
|
||
|
|
||
|
"github.com/tal-tech/go-zero/core/jsonx"
|
||
|
"github.com/tal-tech/go-zero/rpcx"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
Adder interface {
|
||
|
Add(ctx context.Context, in *AddReq) (*AddResp, error)
|
||
|
}
|
||
|
|
||
|
defaultAdder struct {
|
||
|
cli rpcx.Client
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func NewAdder(cli rpcx.Client) Adder {
|
||
|
return &defaultAdder{
|
||
|
cli: cli,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|