forked from yarpc/yarpc-go
/
example.pb.yarpc.go
959 lines (833 loc) · 33 KB
/
example.pb.yarpc.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
// Code generated by protoc-gen-yarpc-go. DO NOT EDIT.
// source: internal/examples/protobuf/examplepb/example.proto
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package examplepb
import (
"context"
"io/ioutil"
"reflect"
"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"
"go.uber.org/fx"
"go.uber.org/yarpc"
"go.uber.org/yarpc/api/transport"
"go.uber.org/yarpc/encoding/protobuf"
"go.uber.org/yarpc/encoding/protobuf/reflection"
"go.uber.org/yarpc/yarpcproto"
)
var _ = ioutil.NopCloser
// KeyValueYARPCClient is the YARPC client-side interface for the KeyValue service.
type KeyValueYARPCClient interface {
GetValue(context.Context, *GetValueRequest, ...yarpc.CallOption) (*GetValueResponse, error)
SetValue(context.Context, *SetValueRequest, ...yarpc.CallOption) (*SetValueResponse, error)
}
func newKeyValueYARPCClient(clientConfig transport.ClientConfig, anyResolver jsonpb.AnyResolver, options ...protobuf.ClientOption) KeyValueYARPCClient {
return &_KeyValueYARPCCaller{protobuf.NewStreamClient(
protobuf.ClientParams{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.KeyValue",
ClientConfig: clientConfig,
AnyResolver: anyResolver,
Options: options,
},
)}
}
// NewKeyValueYARPCClient builds a new YARPC client for the KeyValue service.
func NewKeyValueYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) KeyValueYARPCClient {
return newKeyValueYARPCClient(clientConfig, nil, options...)
}
// KeyValueYARPCServer is the YARPC server-side interface for the KeyValue service.
type KeyValueYARPCServer interface {
GetValue(context.Context, *GetValueRequest) (*GetValueResponse, error)
SetValue(context.Context, *SetValueRequest) (*SetValueResponse, error)
}
type buildKeyValueYARPCProceduresParams struct {
Server KeyValueYARPCServer
AnyResolver jsonpb.AnyResolver
}
func buildKeyValueYARPCProcedures(params buildKeyValueYARPCProceduresParams) []transport.Procedure {
handler := &_KeyValueYARPCHandler{params.Server}
return protobuf.BuildProcedures(
protobuf.BuildProceduresParams{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.KeyValue",
UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{
{
MethodName: "GetValue",
Handler: protobuf.NewUnaryHandler(
protobuf.UnaryHandlerParams{
Handle: handler.GetValue,
NewRequest: newKeyValueServiceGetValueYARPCRequest,
AnyResolver: params.AnyResolver,
},
),
},
{
MethodName: "SetValue",
Handler: protobuf.NewUnaryHandler(
protobuf.UnaryHandlerParams{
Handle: handler.SetValue,
NewRequest: newKeyValueServiceSetValueYARPCRequest,
AnyResolver: params.AnyResolver,
},
),
},
},
OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{},
StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{},
},
)
}
// BuildKeyValueYARPCProcedures prepares an implementation of the KeyValue service for YARPC registration.
func BuildKeyValueYARPCProcedures(server KeyValueYARPCServer) []transport.Procedure {
return buildKeyValueYARPCProcedures(buildKeyValueYARPCProceduresParams{Server: server})
}
// FxKeyValueYARPCClientParams defines the input
// for NewFxKeyValueYARPCClient. It provides the
// paramaters to get a KeyValueYARPCClient in an
// Fx application.
type FxKeyValueYARPCClientParams struct {
fx.In
Provider yarpc.ClientConfig
AnyResolver jsonpb.AnyResolver `name:"yarpcfx" optional:"true"`
}
// FxKeyValueYARPCClientResult defines the output
// of NewFxKeyValueYARPCClient. It provides a
// KeyValueYARPCClient to an Fx application.
type FxKeyValueYARPCClientResult struct {
fx.Out
Client KeyValueYARPCClient
// We are using an fx.Out struct here instead of just returning a client
// so that we can add more values or add named versions of the client in
// the future without breaking any existing code.
}
// NewFxKeyValueYARPCClient provides a KeyValueYARPCClient
// to an Fx application using the given name for routing.
//
// fx.Provide(
// examplepb.NewFxKeyValueYARPCClient("service-name"),
// ...
// )
func NewFxKeyValueYARPCClient(name string, options ...protobuf.ClientOption) interface{} {
return func(params FxKeyValueYARPCClientParams) FxKeyValueYARPCClientResult {
return FxKeyValueYARPCClientResult{
Client: newKeyValueYARPCClient(params.Provider.ClientConfig(name), params.AnyResolver, options...),
}
}
}
// FxKeyValueYARPCProceduresParams defines the input
// for NewFxKeyValueYARPCProcedures. It provides the
// paramaters to get KeyValueYARPCServer procedures in an
// Fx application.
type FxKeyValueYARPCProceduresParams struct {
fx.In
Server KeyValueYARPCServer
AnyResolver jsonpb.AnyResolver `name:"yarpcfx" optional:"true"`
}
// FxKeyValueYARPCProceduresResult defines the output
// of NewFxKeyValueYARPCProcedures. It provides
// KeyValueYARPCServer procedures to an Fx application.
//
// The procedures are provided to the "yarpcfx" value group.
// Dig 1.2 or newer must be used for this feature to work.
type FxKeyValueYARPCProceduresResult struct {
fx.Out
Procedures []transport.Procedure `group:"yarpcfx"`
ReflectionMeta reflection.ServerMeta `group:"yarpcfx"`
}
// NewFxKeyValueYARPCProcedures provides KeyValueYARPCServer procedures to an Fx application.
// It expects a KeyValueYARPCServer to be present in the container.
//
// fx.Provide(
// examplepb.NewFxKeyValueYARPCProcedures(),
// ...
// )
func NewFxKeyValueYARPCProcedures() interface{} {
return func(params FxKeyValueYARPCProceduresParams) FxKeyValueYARPCProceduresResult {
return FxKeyValueYARPCProceduresResult{
Procedures: buildKeyValueYARPCProcedures(buildKeyValueYARPCProceduresParams{
Server: params.Server,
AnyResolver: params.AnyResolver,
}),
ReflectionMeta: reflection.ServerMeta{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.KeyValue",
FileDescriptors: yarpcFileDescriptorClosure43929dec9f67b739,
},
}
}
}
type _KeyValueYARPCCaller struct {
streamClient protobuf.StreamClient
}
func (c *_KeyValueYARPCCaller) GetValue(ctx context.Context, request *GetValueRequest, options ...yarpc.CallOption) (*GetValueResponse, error) {
responseMessage, err := c.streamClient.Call(ctx, "GetValue", request, newKeyValueServiceGetValueYARPCResponse, options...)
if responseMessage == nil {
return nil, err
}
response, ok := responseMessage.(*GetValueResponse)
if !ok {
return nil, protobuf.CastError(emptyKeyValueServiceGetValueYARPCResponse, responseMessage)
}
return response, err
}
func (c *_KeyValueYARPCCaller) SetValue(ctx context.Context, request *SetValueRequest, options ...yarpc.CallOption) (*SetValueResponse, error) {
responseMessage, err := c.streamClient.Call(ctx, "SetValue", request, newKeyValueServiceSetValueYARPCResponse, options...)
if responseMessage == nil {
return nil, err
}
response, ok := responseMessage.(*SetValueResponse)
if !ok {
return nil, protobuf.CastError(emptyKeyValueServiceSetValueYARPCResponse, responseMessage)
}
return response, err
}
type _KeyValueYARPCHandler struct {
server KeyValueYARPCServer
}
func (h *_KeyValueYARPCHandler) GetValue(ctx context.Context, requestMessage proto.Message) (proto.Message, error) {
var request *GetValueRequest
var ok bool
if requestMessage != nil {
request, ok = requestMessage.(*GetValueRequest)
if !ok {
return nil, protobuf.CastError(emptyKeyValueServiceGetValueYARPCRequest, requestMessage)
}
}
response, err := h.server.GetValue(ctx, request)
if response == nil {
return nil, err
}
return response, err
}
func (h *_KeyValueYARPCHandler) SetValue(ctx context.Context, requestMessage proto.Message) (proto.Message, error) {
var request *SetValueRequest
var ok bool
if requestMessage != nil {
request, ok = requestMessage.(*SetValueRequest)
if !ok {
return nil, protobuf.CastError(emptyKeyValueServiceSetValueYARPCRequest, requestMessage)
}
}
response, err := h.server.SetValue(ctx, request)
if response == nil {
return nil, err
}
return response, err
}
func newKeyValueServiceGetValueYARPCRequest() proto.Message {
return &GetValueRequest{}
}
func newKeyValueServiceGetValueYARPCResponse() proto.Message {
return &GetValueResponse{}
}
func newKeyValueServiceSetValueYARPCRequest() proto.Message {
return &SetValueRequest{}
}
func newKeyValueServiceSetValueYARPCResponse() proto.Message {
return &SetValueResponse{}
}
var (
emptyKeyValueServiceGetValueYARPCRequest = &GetValueRequest{}
emptyKeyValueServiceGetValueYARPCResponse = &GetValueResponse{}
emptyKeyValueServiceSetValueYARPCRequest = &SetValueRequest{}
emptyKeyValueServiceSetValueYARPCResponse = &SetValueResponse{}
)
// SinkYARPCClient is the YARPC client-side interface for the Sink service.
type SinkYARPCClient interface {
Fire(context.Context, *FireRequest, ...yarpc.CallOption) (yarpc.Ack, error)
}
func newSinkYARPCClient(clientConfig transport.ClientConfig, anyResolver jsonpb.AnyResolver, options ...protobuf.ClientOption) SinkYARPCClient {
return &_SinkYARPCCaller{protobuf.NewStreamClient(
protobuf.ClientParams{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.Sink",
ClientConfig: clientConfig,
AnyResolver: anyResolver,
Options: options,
},
)}
}
// NewSinkYARPCClient builds a new YARPC client for the Sink service.
func NewSinkYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) SinkYARPCClient {
return newSinkYARPCClient(clientConfig, nil, options...)
}
// SinkYARPCServer is the YARPC server-side interface for the Sink service.
type SinkYARPCServer interface {
Fire(context.Context, *FireRequest) error
}
type buildSinkYARPCProceduresParams struct {
Server SinkYARPCServer
AnyResolver jsonpb.AnyResolver
}
func buildSinkYARPCProcedures(params buildSinkYARPCProceduresParams) []transport.Procedure {
handler := &_SinkYARPCHandler{params.Server}
return protobuf.BuildProcedures(
protobuf.BuildProceduresParams{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.Sink",
UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{},
OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{
{
MethodName: "Fire",
Handler: protobuf.NewOnewayHandler(
protobuf.OnewayHandlerParams{
Handle: handler.Fire,
NewRequest: newSinkServiceFireYARPCRequest,
},
),
},
},
StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{},
},
)
}
// BuildSinkYARPCProcedures prepares an implementation of the Sink service for YARPC registration.
func BuildSinkYARPCProcedures(server SinkYARPCServer) []transport.Procedure {
return buildSinkYARPCProcedures(buildSinkYARPCProceduresParams{Server: server})
}
// FxSinkYARPCClientParams defines the input
// for NewFxSinkYARPCClient. It provides the
// paramaters to get a SinkYARPCClient in an
// Fx application.
type FxSinkYARPCClientParams struct {
fx.In
Provider yarpc.ClientConfig
AnyResolver jsonpb.AnyResolver `name:"yarpcfx" optional:"true"`
}
// FxSinkYARPCClientResult defines the output
// of NewFxSinkYARPCClient. It provides a
// SinkYARPCClient to an Fx application.
type FxSinkYARPCClientResult struct {
fx.Out
Client SinkYARPCClient
// We are using an fx.Out struct here instead of just returning a client
// so that we can add more values or add named versions of the client in
// the future without breaking any existing code.
}
// NewFxSinkYARPCClient provides a SinkYARPCClient
// to an Fx application using the given name for routing.
//
// fx.Provide(
// examplepb.NewFxSinkYARPCClient("service-name"),
// ...
// )
func NewFxSinkYARPCClient(name string, options ...protobuf.ClientOption) interface{} {
return func(params FxSinkYARPCClientParams) FxSinkYARPCClientResult {
return FxSinkYARPCClientResult{
Client: newSinkYARPCClient(params.Provider.ClientConfig(name), params.AnyResolver, options...),
}
}
}
// FxSinkYARPCProceduresParams defines the input
// for NewFxSinkYARPCProcedures. It provides the
// paramaters to get SinkYARPCServer procedures in an
// Fx application.
type FxSinkYARPCProceduresParams struct {
fx.In
Server SinkYARPCServer
AnyResolver jsonpb.AnyResolver `name:"yarpcfx" optional:"true"`
}
// FxSinkYARPCProceduresResult defines the output
// of NewFxSinkYARPCProcedures. It provides
// SinkYARPCServer procedures to an Fx application.
//
// The procedures are provided to the "yarpcfx" value group.
// Dig 1.2 or newer must be used for this feature to work.
type FxSinkYARPCProceduresResult struct {
fx.Out
Procedures []transport.Procedure `group:"yarpcfx"`
ReflectionMeta reflection.ServerMeta `group:"yarpcfx"`
}
// NewFxSinkYARPCProcedures provides SinkYARPCServer procedures to an Fx application.
// It expects a SinkYARPCServer to be present in the container.
//
// fx.Provide(
// examplepb.NewFxSinkYARPCProcedures(),
// ...
// )
func NewFxSinkYARPCProcedures() interface{} {
return func(params FxSinkYARPCProceduresParams) FxSinkYARPCProceduresResult {
return FxSinkYARPCProceduresResult{
Procedures: buildSinkYARPCProcedures(buildSinkYARPCProceduresParams{
Server: params.Server,
AnyResolver: params.AnyResolver,
}),
ReflectionMeta: reflection.ServerMeta{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.Sink",
FileDescriptors: yarpcFileDescriptorClosure43929dec9f67b739,
},
}
}
}
type _SinkYARPCCaller struct {
streamClient protobuf.StreamClient
}
func (c *_SinkYARPCCaller) Fire(ctx context.Context, request *FireRequest, options ...yarpc.CallOption) (yarpc.Ack, error) {
return c.streamClient.CallOneway(ctx, "Fire", request, options...)
}
type _SinkYARPCHandler struct {
server SinkYARPCServer
}
func (h *_SinkYARPCHandler) Fire(ctx context.Context, requestMessage proto.Message) error {
var request *FireRequest
var ok bool
if requestMessage != nil {
request, ok = requestMessage.(*FireRequest)
if !ok {
return protobuf.CastError(emptySinkServiceFireYARPCRequest, requestMessage)
}
}
return h.server.Fire(ctx, request)
}
func newSinkServiceFireYARPCRequest() proto.Message {
return &FireRequest{}
}
func newSinkServiceFireYARPCResponse() proto.Message {
return &yarpcproto.Oneway{}
}
var (
emptySinkServiceFireYARPCRequest = &FireRequest{}
emptySinkServiceFireYARPCResponse = &yarpcproto.Oneway{}
)
// FooYARPCClient is the YARPC client-side interface for the Foo service.
type FooYARPCClient interface {
EchoOut(context.Context, ...yarpc.CallOption) (FooServiceEchoOutYARPCClient, error)
EchoIn(context.Context, *EchoInRequest, ...yarpc.CallOption) (FooServiceEchoInYARPCClient, error)
EchoBoth(context.Context, ...yarpc.CallOption) (FooServiceEchoBothYARPCClient, error)
}
// FooServiceEchoOutYARPCClient sends EchoOutRequests and receives the single EchoOutResponse when sending is done.
type FooServiceEchoOutYARPCClient interface {
Context() context.Context
Send(*EchoOutRequest, ...yarpc.StreamOption) error
CloseAndRecv(...yarpc.StreamOption) (*EchoOutResponse, error)
}
// FooServiceEchoInYARPCClient receives EchoInResponses, returning io.EOF when the stream is complete.
type FooServiceEchoInYARPCClient interface {
Context() context.Context
Recv(...yarpc.StreamOption) (*EchoInResponse, error)
CloseSend(...yarpc.StreamOption) error
}
// FooServiceEchoBothYARPCClient sends EchoBothRequests and receives EchoBothResponses, returning io.EOF when the stream is complete.
type FooServiceEchoBothYARPCClient interface {
Context() context.Context
Send(*EchoBothRequest, ...yarpc.StreamOption) error
Recv(...yarpc.StreamOption) (*EchoBothResponse, error)
CloseSend(...yarpc.StreamOption) error
}
func newFooYARPCClient(clientConfig transport.ClientConfig, anyResolver jsonpb.AnyResolver, options ...protobuf.ClientOption) FooYARPCClient {
return &_FooYARPCCaller{protobuf.NewStreamClient(
protobuf.ClientParams{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.Foo",
ClientConfig: clientConfig,
AnyResolver: anyResolver,
Options: options,
},
)}
}
// NewFooYARPCClient builds a new YARPC client for the Foo service.
func NewFooYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) FooYARPCClient {
return newFooYARPCClient(clientConfig, nil, options...)
}
// FooYARPCServer is the YARPC server-side interface for the Foo service.
type FooYARPCServer interface {
EchoOut(FooServiceEchoOutYARPCServer) (*EchoOutResponse, error)
EchoIn(*EchoInRequest, FooServiceEchoInYARPCServer) error
EchoBoth(FooServiceEchoBothYARPCServer) error
}
// FooServiceEchoOutYARPCServer receives EchoOutRequests.
type FooServiceEchoOutYARPCServer interface {
Context() context.Context
Recv(...yarpc.StreamOption) (*EchoOutRequest, error)
}
// FooServiceEchoInYARPCServer sends EchoInResponses.
type FooServiceEchoInYARPCServer interface {
Context() context.Context
Send(*EchoInResponse, ...yarpc.StreamOption) error
}
// FooServiceEchoBothYARPCServer receives EchoBothRequests and sends EchoBothResponse.
type FooServiceEchoBothYARPCServer interface {
Context() context.Context
Recv(...yarpc.StreamOption) (*EchoBothRequest, error)
Send(*EchoBothResponse, ...yarpc.StreamOption) error
}
type buildFooYARPCProceduresParams struct {
Server FooYARPCServer
AnyResolver jsonpb.AnyResolver
}
func buildFooYARPCProcedures(params buildFooYARPCProceduresParams) []transport.Procedure {
handler := &_FooYARPCHandler{params.Server}
return protobuf.BuildProcedures(
protobuf.BuildProceduresParams{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.Foo",
UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{},
OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{},
StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{
{
MethodName: "EchoBoth",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.EchoBoth,
},
),
},
{
MethodName: "EchoIn",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.EchoIn,
},
),
},
{
MethodName: "EchoOut",
Handler: protobuf.NewStreamHandler(
protobuf.StreamHandlerParams{
Handle: handler.EchoOut,
},
),
},
},
},
)
}
// BuildFooYARPCProcedures prepares an implementation of the Foo service for YARPC registration.
func BuildFooYARPCProcedures(server FooYARPCServer) []transport.Procedure {
return buildFooYARPCProcedures(buildFooYARPCProceduresParams{Server: server})
}
// FxFooYARPCClientParams defines the input
// for NewFxFooYARPCClient. It provides the
// paramaters to get a FooYARPCClient in an
// Fx application.
type FxFooYARPCClientParams struct {
fx.In
Provider yarpc.ClientConfig
AnyResolver jsonpb.AnyResolver `name:"yarpcfx" optional:"true"`
}
// FxFooYARPCClientResult defines the output
// of NewFxFooYARPCClient. It provides a
// FooYARPCClient to an Fx application.
type FxFooYARPCClientResult struct {
fx.Out
Client FooYARPCClient
// We are using an fx.Out struct here instead of just returning a client
// so that we can add more values or add named versions of the client in
// the future without breaking any existing code.
}
// NewFxFooYARPCClient provides a FooYARPCClient
// to an Fx application using the given name for routing.
//
// fx.Provide(
// examplepb.NewFxFooYARPCClient("service-name"),
// ...
// )
func NewFxFooYARPCClient(name string, options ...protobuf.ClientOption) interface{} {
return func(params FxFooYARPCClientParams) FxFooYARPCClientResult {
return FxFooYARPCClientResult{
Client: newFooYARPCClient(params.Provider.ClientConfig(name), params.AnyResolver, options...),
}
}
}
// FxFooYARPCProceduresParams defines the input
// for NewFxFooYARPCProcedures. It provides the
// paramaters to get FooYARPCServer procedures in an
// Fx application.
type FxFooYARPCProceduresParams struct {
fx.In
Server FooYARPCServer
AnyResolver jsonpb.AnyResolver `name:"yarpcfx" optional:"true"`
}
// FxFooYARPCProceduresResult defines the output
// of NewFxFooYARPCProcedures. It provides
// FooYARPCServer procedures to an Fx application.
//
// The procedures are provided to the "yarpcfx" value group.
// Dig 1.2 or newer must be used for this feature to work.
type FxFooYARPCProceduresResult struct {
fx.Out
Procedures []transport.Procedure `group:"yarpcfx"`
ReflectionMeta reflection.ServerMeta `group:"yarpcfx"`
}
// NewFxFooYARPCProcedures provides FooYARPCServer procedures to an Fx application.
// It expects a FooYARPCServer to be present in the container.
//
// fx.Provide(
// examplepb.NewFxFooYARPCProcedures(),
// ...
// )
func NewFxFooYARPCProcedures() interface{} {
return func(params FxFooYARPCProceduresParams) FxFooYARPCProceduresResult {
return FxFooYARPCProceduresResult{
Procedures: buildFooYARPCProcedures(buildFooYARPCProceduresParams{
Server: params.Server,
AnyResolver: params.AnyResolver,
}),
ReflectionMeta: reflection.ServerMeta{
ServiceName: "uber.yarpc.internal.examples.protobuf.example.Foo",
FileDescriptors: yarpcFileDescriptorClosure43929dec9f67b739,
},
}
}
}
type _FooYARPCCaller struct {
streamClient protobuf.StreamClient
}
func (c *_FooYARPCCaller) EchoOut(ctx context.Context, options ...yarpc.CallOption) (FooServiceEchoOutYARPCClient, error) {
stream, err := c.streamClient.CallStream(ctx, "EchoOut", options...)
if err != nil {
return nil, err
}
return &_FooServiceEchoOutYARPCClient{stream: stream}, nil
}
func (c *_FooYARPCCaller) EchoIn(ctx context.Context, request *EchoInRequest, options ...yarpc.CallOption) (FooServiceEchoInYARPCClient, error) {
stream, err := c.streamClient.CallStream(ctx, "EchoIn", options...)
if err != nil {
return nil, err
}
if err := stream.Send(request); err != nil {
return nil, err
}
return &_FooServiceEchoInYARPCClient{stream: stream}, nil
}
func (c *_FooYARPCCaller) EchoBoth(ctx context.Context, options ...yarpc.CallOption) (FooServiceEchoBothYARPCClient, error) {
stream, err := c.streamClient.CallStream(ctx, "EchoBoth", options...)
if err != nil {
return nil, err
}
return &_FooServiceEchoBothYARPCClient{stream: stream}, nil
}
type _FooYARPCHandler struct {
server FooYARPCServer
}
func (h *_FooYARPCHandler) EchoOut(serverStream *protobuf.ServerStream) error {
response, err := h.server.EchoOut(&_FooServiceEchoOutYARPCServer{serverStream: serverStream})
if err != nil {
return err
}
return serverStream.Send(response)
}
func (h *_FooYARPCHandler) EchoIn(serverStream *protobuf.ServerStream) error {
requestMessage, err := serverStream.Receive(newFooServiceEchoInYARPCRequest)
if requestMessage == nil {
return err
}
request, ok := requestMessage.(*EchoInRequest)
if !ok {
return protobuf.CastError(emptyFooServiceEchoInYARPCRequest, requestMessage)
}
return h.server.EchoIn(request, &_FooServiceEchoInYARPCServer{serverStream: serverStream})
}
func (h *_FooYARPCHandler) EchoBoth(serverStream *protobuf.ServerStream) error {
return h.server.EchoBoth(&_FooServiceEchoBothYARPCServer{serverStream: serverStream})
}
type _FooServiceEchoOutYARPCClient struct {
stream *protobuf.ClientStream
}
func (c *_FooServiceEchoOutYARPCClient) Context() context.Context {
return c.stream.Context()
}
func (c *_FooServiceEchoOutYARPCClient) Send(request *EchoOutRequest, options ...yarpc.StreamOption) error {
return c.stream.Send(request, options...)
}
func (c *_FooServiceEchoOutYARPCClient) CloseAndRecv(options ...yarpc.StreamOption) (*EchoOutResponse, error) {
if err := c.stream.Close(options...); err != nil {
return nil, err
}
responseMessage, err := c.stream.Receive(newFooServiceEchoOutYARPCResponse, options...)
if responseMessage == nil {
return nil, err
}
response, ok := responseMessage.(*EchoOutResponse)
if !ok {
return nil, protobuf.CastError(emptyFooServiceEchoOutYARPCResponse, responseMessage)
}
return response, err
}
type _FooServiceEchoInYARPCClient struct {
stream *protobuf.ClientStream
}
func (c *_FooServiceEchoInYARPCClient) Context() context.Context {
return c.stream.Context()
}
func (c *_FooServiceEchoInYARPCClient) Recv(options ...yarpc.StreamOption) (*EchoInResponse, error) {
responseMessage, err := c.stream.Receive(newFooServiceEchoInYARPCResponse, options...)
if responseMessage == nil {
return nil, err
}
response, ok := responseMessage.(*EchoInResponse)
if !ok {
return nil, protobuf.CastError(emptyFooServiceEchoInYARPCResponse, responseMessage)
}
return response, err
}
func (c *_FooServiceEchoInYARPCClient) CloseSend(options ...yarpc.StreamOption) error {
return c.stream.Close(options...)
}
type _FooServiceEchoBothYARPCClient struct {
stream *protobuf.ClientStream
}
func (c *_FooServiceEchoBothYARPCClient) Context() context.Context {
return c.stream.Context()
}
func (c *_FooServiceEchoBothYARPCClient) Send(request *EchoBothRequest, options ...yarpc.StreamOption) error {
return c.stream.Send(request, options...)
}
func (c *_FooServiceEchoBothYARPCClient) Recv(options ...yarpc.StreamOption) (*EchoBothResponse, error) {
responseMessage, err := c.stream.Receive(newFooServiceEchoBothYARPCResponse, options...)
if responseMessage == nil {
return nil, err
}
response, ok := responseMessage.(*EchoBothResponse)
if !ok {
return nil, protobuf.CastError(emptyFooServiceEchoBothYARPCResponse, responseMessage)
}
return response, err
}
func (c *_FooServiceEchoBothYARPCClient) CloseSend(options ...yarpc.StreamOption) error {
return c.stream.Close(options...)
}
type _FooServiceEchoOutYARPCServer struct {
serverStream *protobuf.ServerStream
}
func (s *_FooServiceEchoOutYARPCServer) Context() context.Context {
return s.serverStream.Context()
}
func (s *_FooServiceEchoOutYARPCServer) Recv(options ...yarpc.StreamOption) (*EchoOutRequest, error) {
requestMessage, err := s.serverStream.Receive(newFooServiceEchoOutYARPCRequest, options...)
if requestMessage == nil {
return nil, err
}
request, ok := requestMessage.(*EchoOutRequest)
if !ok {
return nil, protobuf.CastError(emptyFooServiceEchoOutYARPCRequest, requestMessage)
}
return request, err
}
type _FooServiceEchoInYARPCServer struct {
serverStream *protobuf.ServerStream
}
func (s *_FooServiceEchoInYARPCServer) Context() context.Context {
return s.serverStream.Context()
}
func (s *_FooServiceEchoInYARPCServer) Send(response *EchoInResponse, options ...yarpc.StreamOption) error {
return s.serverStream.Send(response, options...)
}
type _FooServiceEchoBothYARPCServer struct {
serverStream *protobuf.ServerStream
}
func (s *_FooServiceEchoBothYARPCServer) Context() context.Context {
return s.serverStream.Context()
}
func (s *_FooServiceEchoBothYARPCServer) Recv(options ...yarpc.StreamOption) (*EchoBothRequest, error) {
requestMessage, err := s.serverStream.Receive(newFooServiceEchoBothYARPCRequest, options...)
if requestMessage == nil {
return nil, err
}
request, ok := requestMessage.(*EchoBothRequest)
if !ok {
return nil, protobuf.CastError(emptyFooServiceEchoBothYARPCRequest, requestMessage)
}
return request, err
}
func (s *_FooServiceEchoBothYARPCServer) Send(response *EchoBothResponse, options ...yarpc.StreamOption) error {
return s.serverStream.Send(response, options...)
}
func newFooServiceEchoOutYARPCRequest() proto.Message {
return &EchoOutRequest{}
}
func newFooServiceEchoOutYARPCResponse() proto.Message {
return &EchoOutResponse{}
}
func newFooServiceEchoInYARPCRequest() proto.Message {
return &EchoInRequest{}
}
func newFooServiceEchoInYARPCResponse() proto.Message {
return &EchoInResponse{}
}
func newFooServiceEchoBothYARPCRequest() proto.Message {
return &EchoBothRequest{}
}
func newFooServiceEchoBothYARPCResponse() proto.Message {
return &EchoBothResponse{}
}
var (
emptyFooServiceEchoOutYARPCRequest = &EchoOutRequest{}
emptyFooServiceEchoOutYARPCResponse = &EchoOutResponse{}
emptyFooServiceEchoInYARPCRequest = &EchoInRequest{}
emptyFooServiceEchoInYARPCResponse = &EchoInResponse{}
emptyFooServiceEchoBothYARPCRequest = &EchoBothRequest{}
emptyFooServiceEchoBothYARPCResponse = &EchoBothResponse{}
)
var yarpcFileDescriptorClosure43929dec9f67b739 = [][]byte{
// internal/examples/protobuf/examplepb/example.proto
[]byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xd1, 0x6e, 0x94, 0x40,
0x14, 0xdd, 0x59, 0x6a, 0xbb, 0x7b, 0xb7, 0x75, 0xc9, 0x8d, 0x31, 0x84, 0xa7, 0xca, 0xbe, 0x10,
0xa3, 0x6c, 0x83, 0xbe, 0x68, 0x6c, 0x4d, 0x9a, 0x58, 0x63, 0x8c, 0xd6, 0x40, 0x62, 0x8c, 0x2f,
0x75, 0x68, 0x46, 0xbb, 0x59, 0x18, 0x90, 0x01, 0x95, 0x4f, 0x30, 0xd1, 0x07, 0x7f, 0xc3, 0x67,
0x3f, 0xd0, 0x30, 0x30, 0x2c, 0xae, 0xd9, 0x6c, 0x40, 0xdf, 0x66, 0x2e, 0xe7, 0x9c, 0x7b, 0x2e,
0x9c, 0x0b, 0xb8, 0x0b, 0x9e, 0xb1, 0x94, 0xd3, 0x70, 0xce, 0xbe, 0xd0, 0x28, 0x09, 0x99, 0x98,
0x27, 0x69, 0x9c, 0xc5, 0x41, 0xfe, 0x5e, 0x55, 0x92, 0x40, 0x9d, 0x1c, 0xf9, 0x08, 0xef, 0xe6,
0x01, 0x4b, 0x9d, 0x82, 0xa6, 0xc9, 0xa5, 0xa3, 0xe8, 0x8e, 0xa2, 0x3b, 0x8a, 0xae, 0x2a, 0xe6,
0x4d, 0x89, 0x94, 0xe5, 0x79, 0x45, 0x92, 0x67, 0x6b, 0x06, 0xd3, 0xa7, 0x2c, 0x7b, 0x4d, 0xc3,
0x9c, 0x79, 0xec, 0x63, 0xce, 0x44, 0x86, 0x3a, 0x68, 0x4b, 0x56, 0x18, 0xe4, 0x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e9, 0xc4,
0x13, 0xc5, 0x85, 0x30, 0x21, 0x89, 0x0d, 0x4c, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x71,
0x5c, 0xc2, 0xd9, 0x56, 0x00, 0x00, 0x00,
},
}
func init() {
yarpc.RegisterClientBuilder(
func(clientConfig transport.ClientConfig, structField reflect.StructField) KeyValueYARPCClient {
return NewKeyValueYARPCClient(clientConfig, protobuf.ClientBuilderOptions(clientConfig, structField)...)
},
)
yarpc.RegisterClientBuilder(
func(clientConfig transport.ClientConfig, structField reflect.StructField) SinkYARPCClient {
return NewSinkYARPCClient(clientConfig, protobuf.ClientBuilderOptions(clientConfig, structField)...)
},
)
yarpc.RegisterClientBuilder(
func(clientConfig transport.ClientConfig, structField reflect.StructField) FooYARPCClient {
return NewFooYARPCClient(clientConfig, protobuf.ClientBuilderOptions(clientConfig, structField)...)
},
)
}