-
Notifications
You must be signed in to change notification settings - Fork 0
/
favoriteservice.go
360 lines (309 loc) · 8.52 KB
/
favoriteservice.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// Code generated by Kitex v0.4.4. DO NOT EDIT.
package favoriteservice
import (
"context"
"fmt"
"github.com/132982317/profstik/kitex_gen/favorite"
client "github.com/cloudwego/kitex/client"
kitex "github.com/cloudwego/kitex/pkg/serviceinfo"
streaming "github.com/cloudwego/kitex/pkg/streaming"
proto "google.golang.org/protobuf/proto"
)
func serviceInfo() *kitex.ServiceInfo {
return favoriteServiceServiceInfo
}
var favoriteServiceServiceInfo = NewServiceInfo()
func NewServiceInfo() *kitex.ServiceInfo {
serviceName := "FavoriteService"
handlerType := (*favorite.FavoriteService)(nil)
methods := map[string]kitex.MethodInfo{
"FavoriteAction": kitex.NewMethodInfo(favoriteActionHandler, newFavoriteActionArgs, newFavoriteActionResult, false),
"FavoriteList": kitex.NewMethodInfo(favoriteListHandler, newFavoriteListArgs, newFavoriteListResult, false),
}
extra := map[string]interface{}{
"PackageName": "favorite",
}
svcInfo := &kitex.ServiceInfo{
ServiceName: serviceName,
HandlerType: handlerType,
Methods: methods,
PayloadCodec: kitex.Protobuf,
KiteXGenVersion: "v0.4.4",
Extra: extra,
}
return svcInfo
}
func favoriteActionHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
switch s := arg.(type) {
case *streaming.Args:
st := s.Stream
req := new(favorite.FavoriteActionRequest)
if err := st.RecvMsg(req); err != nil {
return err
}
resp, err := handler.(favorite.FavoriteService).FavoriteAction(ctx, req)
if err != nil {
return err
}
if err := st.SendMsg(resp); err != nil {
return err
}
case *FavoriteActionArgs:
success, err := handler.(favorite.FavoriteService).FavoriteAction(ctx, s.Req)
if err != nil {
return err
}
realResult := result.(*FavoriteActionResult)
realResult.Success = success
}
return nil
}
func newFavoriteActionArgs() interface{} {
return &FavoriteActionArgs{}
}
func newFavoriteActionResult() interface{} {
return &FavoriteActionResult{}
}
type FavoriteActionArgs struct {
Req *favorite.FavoriteActionRequest
}
func (p *FavoriteActionArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
if !p.IsSetReq() {
p.Req = new(favorite.FavoriteActionRequest)
}
return p.Req.FastRead(buf, _type, number)
}
func (p *FavoriteActionArgs) FastWrite(buf []byte) (n int) {
if !p.IsSetReq() {
return 0
}
return p.Req.FastWrite(buf)
}
func (p *FavoriteActionArgs) Size() (n int) {
if !p.IsSetReq() {
return 0
}
return p.Req.Size()
}
func (p *FavoriteActionArgs) Marshal(out []byte) ([]byte, error) {
if !p.IsSetReq() {
return out, fmt.Errorf("No req in FavoriteActionArgs")
}
return proto.Marshal(p.Req)
}
func (p *FavoriteActionArgs) Unmarshal(in []byte) error {
msg := new(favorite.FavoriteActionRequest)
if err := proto.Unmarshal(in, msg); err != nil {
return err
}
p.Req = msg
return nil
}
var FavoriteActionArgs_Req_DEFAULT *favorite.FavoriteActionRequest
func (p *FavoriteActionArgs) GetReq() *favorite.FavoriteActionRequest {
if !p.IsSetReq() {
return FavoriteActionArgs_Req_DEFAULT
}
return p.Req
}
func (p *FavoriteActionArgs) IsSetReq() bool {
return p.Req != nil
}
type FavoriteActionResult struct {
Success *favorite.FavoriteActionResponse
}
var FavoriteActionResult_Success_DEFAULT *favorite.FavoriteActionResponse
func (p *FavoriteActionResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
if !p.IsSetSuccess() {
p.Success = new(favorite.FavoriteActionResponse)
}
return p.Success.FastRead(buf, _type, number)
}
func (p *FavoriteActionResult) FastWrite(buf []byte) (n int) {
if !p.IsSetSuccess() {
return 0
}
return p.Success.FastWrite(buf)
}
func (p *FavoriteActionResult) Size() (n int) {
if !p.IsSetSuccess() {
return 0
}
return p.Success.Size()
}
func (p *FavoriteActionResult) Marshal(out []byte) ([]byte, error) {
if !p.IsSetSuccess() {
return out, fmt.Errorf("No req in FavoriteActionResult")
}
return proto.Marshal(p.Success)
}
func (p *FavoriteActionResult) Unmarshal(in []byte) error {
msg := new(favorite.FavoriteActionResponse)
if err := proto.Unmarshal(in, msg); err != nil {
return err
}
p.Success = msg
return nil
}
func (p *FavoriteActionResult) GetSuccess() *favorite.FavoriteActionResponse {
if !p.IsSetSuccess() {
return FavoriteActionResult_Success_DEFAULT
}
return p.Success
}
func (p *FavoriteActionResult) SetSuccess(x interface{}) {
p.Success = x.(*favorite.FavoriteActionResponse)
}
func (p *FavoriteActionResult) IsSetSuccess() bool {
return p.Success != nil
}
func favoriteListHandler(ctx context.Context, handler interface{}, arg, result interface{}) error {
switch s := arg.(type) {
case *streaming.Args:
st := s.Stream
req := new(favorite.FavoriteListRequest)
if err := st.RecvMsg(req); err != nil {
return err
}
resp, err := handler.(favorite.FavoriteService).FavoriteList(ctx, req)
if err != nil {
return err
}
if err := st.SendMsg(resp); err != nil {
return err
}
case *FavoriteListArgs:
success, err := handler.(favorite.FavoriteService).FavoriteList(ctx, s.Req)
if err != nil {
return err
}
realResult := result.(*FavoriteListResult)
realResult.Success = success
}
return nil
}
func newFavoriteListArgs() interface{} {
return &FavoriteListArgs{}
}
func newFavoriteListResult() interface{} {
return &FavoriteListResult{}
}
type FavoriteListArgs struct {
Req *favorite.FavoriteListRequest
}
func (p *FavoriteListArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
if !p.IsSetReq() {
p.Req = new(favorite.FavoriteListRequest)
}
return p.Req.FastRead(buf, _type, number)
}
func (p *FavoriteListArgs) FastWrite(buf []byte) (n int) {
if !p.IsSetReq() {
return 0
}
return p.Req.FastWrite(buf)
}
func (p *FavoriteListArgs) Size() (n int) {
if !p.IsSetReq() {
return 0
}
return p.Req.Size()
}
func (p *FavoriteListArgs) Marshal(out []byte) ([]byte, error) {
if !p.IsSetReq() {
return out, fmt.Errorf("No req in FavoriteListArgs")
}
return proto.Marshal(p.Req)
}
func (p *FavoriteListArgs) Unmarshal(in []byte) error {
msg := new(favorite.FavoriteListRequest)
if err := proto.Unmarshal(in, msg); err != nil {
return err
}
p.Req = msg
return nil
}
var FavoriteListArgs_Req_DEFAULT *favorite.FavoriteListRequest
func (p *FavoriteListArgs) GetReq() *favorite.FavoriteListRequest {
if !p.IsSetReq() {
return FavoriteListArgs_Req_DEFAULT
}
return p.Req
}
func (p *FavoriteListArgs) IsSetReq() bool {
return p.Req != nil
}
type FavoriteListResult struct {
Success *favorite.FavoriteListResponse
}
var FavoriteListResult_Success_DEFAULT *favorite.FavoriteListResponse
func (p *FavoriteListResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) {
if !p.IsSetSuccess() {
p.Success = new(favorite.FavoriteListResponse)
}
return p.Success.FastRead(buf, _type, number)
}
func (p *FavoriteListResult) FastWrite(buf []byte) (n int) {
if !p.IsSetSuccess() {
return 0
}
return p.Success.FastWrite(buf)
}
func (p *FavoriteListResult) Size() (n int) {
if !p.IsSetSuccess() {
return 0
}
return p.Success.Size()
}
func (p *FavoriteListResult) Marshal(out []byte) ([]byte, error) {
if !p.IsSetSuccess() {
return out, fmt.Errorf("No req in FavoriteListResult")
}
return proto.Marshal(p.Success)
}
func (p *FavoriteListResult) Unmarshal(in []byte) error {
msg := new(favorite.FavoriteListResponse)
if err := proto.Unmarshal(in, msg); err != nil {
return err
}
p.Success = msg
return nil
}
func (p *FavoriteListResult) GetSuccess() *favorite.FavoriteListResponse {
if !p.IsSetSuccess() {
return FavoriteListResult_Success_DEFAULT
}
return p.Success
}
func (p *FavoriteListResult) SetSuccess(x interface{}) {
p.Success = x.(*favorite.FavoriteListResponse)
}
func (p *FavoriteListResult) 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) FavoriteAction(ctx context.Context, Req *favorite.FavoriteActionRequest) (r *favorite.FavoriteActionResponse, err error) {
var _args FavoriteActionArgs
_args.Req = Req
var _result FavoriteActionResult
if err = p.c.Call(ctx, "FavoriteAction", &_args, &_result); err != nil {
return
}
return _result.GetSuccess(), nil
}
func (p *kClient) FavoriteList(ctx context.Context, Req *favorite.FavoriteListRequest) (r *favorite.FavoriteListResponse, err error) {
var _args FavoriteListArgs
_args.Req = Req
var _result FavoriteListResult
if err = p.c.Call(ctx, "FavoriteList", &_args, &_result); err != nil {
return
}
return _result.GetSuccess(), nil
}