/
servicea.go
173 lines (144 loc) · 3.66 KB
/
servicea.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Code generated by Kitex v0.3.2. DO NOT EDIT.
package servicea
import (
"context"
"fmt"
"github.com/cloudwego/kitex-examples/grpcproxy/kitex_gen/grpcproxy"
"github.com/cloudwego/kitex/client"
kitex "github.com/cloudwego/kitex/pkg/serviceinfo"
"github.com/cloudwego/kitex/pkg/streaming"
"google.golang.org/protobuf/proto"
)
func serviceInfo() *kitex.ServiceInfo {
return serviceAServiceInfo
}
var serviceAServiceInfo = NewServiceInfo()
func NewServiceInfo() *kitex.ServiceInfo {
serviceName := "ServiceA"
handlerType := (*grpcproxy.ServiceA)(nil)
methods := map[string]kitex.MethodInfo{
"Chat": kitex.NewMethodInfo(chatHandler, newChatArgs, newChatResult, false),
}
extra := map[string]interface{}{
"PackageName": "grpcproxy",
}
extra["streaming"] = true
svcInfo := &kitex.ServiceInfo{
ServiceName: serviceName,
HandlerType: handlerType,
Methods: methods,
PayloadCodec: kitex.Protobuf,
KiteXGenVersion: "v0.3.2",
Extra: extra,
}
return svcInfo
}
func chatHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
st := arg.(*streaming.Args).Stream
stream := &serviceAChatServer{st}
return handler.(grpcproxy.ServiceA).Chat(stream)
}
type serviceAChatClient struct {
streaming.Stream
}
func (x *serviceAChatClient) Send(m *grpcproxy.Request) error {
return x.Stream.SendMsg(m)
}
func (x *serviceAChatClient) Recv() (*grpcproxy.Reply, error) {
m := new(grpcproxy.Reply)
return m, x.Stream.RecvMsg(m)
}
type serviceAChatServer struct {
streaming.Stream
}
func (x *serviceAChatServer) Send(m *grpcproxy.Reply) error {
return x.Stream.SendMsg(m)
}
func (x *serviceAChatServer) Recv() (*grpcproxy.Request, error) {
m := new(grpcproxy.Request)
return m, x.Stream.RecvMsg(m)
}
func newChatArgs() interface{} {
return &ChatArgs{}
}
func newChatResult() interface{} {
return &ChatResult{}
}
type ChatArgs struct {
Req *grpcproxy.Request
}
func (p *ChatArgs) Marshal(out []byte) ([]byte, error) {
if !p.IsSetReq() {
return out, fmt.Errorf("No req in ChatArgs")
}
return proto.Marshal(p.Req)
}
func (p *ChatArgs) Unmarshal(in []byte) error {
msg := new(grpcproxy.Request)
if err := proto.Unmarshal(in, msg); err != nil {
return err
}
p.Req = msg
return nil
}
var ChatArgs_Req_DEFAULT *grpcproxy.Request
func (p *ChatArgs) GetReq() *grpcproxy.Request {
if !p.IsSetReq() {
return ChatArgs_Req_DEFAULT
}
return p.Req
}
func (p *ChatArgs) IsSetReq() bool {
return p.Req != nil
}
type ChatResult struct {
Success *grpcproxy.Reply
}
var ChatResult_Success_DEFAULT *grpcproxy.Reply
func (p *ChatResult) Marshal(out []byte) ([]byte, error) {
if !p.IsSetSuccess() {
return out, fmt.Errorf("No req in ChatResult")
}
return proto.Marshal(p.Success)
}
func (p *ChatResult) Unmarshal(in []byte) error {
msg := new(grpcproxy.Reply)
if err := proto.Unmarshal(in, msg); err != nil {
return err
}
p.Success = msg
return nil
}
func (p *ChatResult) GetSuccess() *grpcproxy.Reply {
if !p.IsSetSuccess() {
return ChatResult_Success_DEFAULT
}
return p.Success
}
func (p *ChatResult) SetSuccess(x interface{}) {
p.Success = x.(*grpcproxy.Reply)
}
func (p *ChatResult) IsSetSuccess() bool {
return p.Success != nil
}
type kClient struct {
c client.Client
}
func newServiceClient(c client.Client) *kClient {
return &kClient{
c: c,
}
}
func (p *kClient) Chat(ctx context.Context) (ServiceA_ChatClient, error) {
streamClient, ok := p.c.(client.Streaming)
if !ok {
return nil, fmt.Errorf("client not support streaming")
}
res := new(streaming.Result)
err := streamClient.Stream(ctx, "Chat", nil, res)
if err != nil {
return nil, err
}
stream := &serviceAChatClient{res.Stream}
return stream, nil
}