-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.pb.proxy.go
676 lines (542 loc) · 22.5 KB
/
example.pb.proxy.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
// Code generated by aws-grpc-service-proxy. DO NOT EDIT.
package proto
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"io"
"math"
"net"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/golang/protobuf/jsonpb"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
grpc_health_v1 "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/keepalive"
api "github.com/katallaxie/protoc-gen-cloud-proxy/api"
o "github.com/katallaxie/protoc-gen-cloud-proxy/pkg/opts"
"github.com/katallaxie/protoc-gen-cloud-proxy/pkg/proxy"
)
// SongJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of SongJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var SongJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Song) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := SongJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Song)(nil)
// SongJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Song. This struct is safe to replace or modify but
// should not be done so concurrently.
var SongJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Song) UnmarshalJSON(b []byte) error {
return SongJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Song)(nil)
// InsertJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of InsertJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var InsertJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Insert) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := InsertJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Insert)(nil)
// InsertJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Insert. This struct is safe to replace or modify but
// should not be done so concurrently.
var InsertJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Insert) UnmarshalJSON(b []byte) error {
return InsertJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Insert)(nil)
// Insert_RequestJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of Insert_RequestJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var Insert_RequestJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Insert_Request) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := Insert_RequestJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Insert_Request)(nil)
// Insert_RequestJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Insert_Request. This struct is safe to replace or modify but
// should not be done so concurrently.
var Insert_RequestJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Insert_Request) UnmarshalJSON(b []byte) error {
return Insert_RequestJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Insert_Request)(nil)
// Insert_ResponseJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of Insert_ResponseJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var Insert_ResponseJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Insert_Response) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := Insert_ResponseJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Insert_Response)(nil)
// Insert_ResponseJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Insert_Response. This struct is safe to replace or modify but
// should not be done so concurrently.
var Insert_ResponseJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Insert_Response) UnmarshalJSON(b []byte) error {
return Insert_ResponseJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Insert_Response)(nil)
// UpdateJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of UpdateJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var UpdateJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Update) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := UpdateJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Update)(nil)
// UpdateJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Update. This struct is safe to replace or modify but
// should not be done so concurrently.
var UpdateJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Update) UnmarshalJSON(b []byte) error {
return UpdateJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Update)(nil)
// Update_RequestJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of Update_RequestJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var Update_RequestJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Update_Request) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := Update_RequestJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Update_Request)(nil)
// Update_RequestJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Update_Request. This struct is safe to replace or modify but
// should not be done so concurrently.
var Update_RequestJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Update_Request) UnmarshalJSON(b []byte) error {
return Update_RequestJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Update_Request)(nil)
// Update_ResponseJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of Update_ResponseJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var Update_ResponseJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Update_Response) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := Update_ResponseJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Update_Response)(nil)
// Update_ResponseJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Update_Response. This struct is safe to replace or modify but
// should not be done so concurrently.
var Update_ResponseJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Update_Response) UnmarshalJSON(b []byte) error {
return Update_ResponseJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Update_Response)(nil)
// ListSongsJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of ListSongsJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var ListSongsJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *ListSongs) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := ListSongsJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*ListSongs)(nil)
// ListSongsJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of ListSongs. This struct is safe to replace or modify but
// should not be done so concurrently.
var ListSongsJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *ListSongs) UnmarshalJSON(b []byte) error {
return ListSongsJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*ListSongs)(nil)
// ListSongs_RequestJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of ListSongs_RequestJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var ListSongs_RequestJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *ListSongs_Request) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := ListSongs_RequestJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*ListSongs_Request)(nil)
// ListSongs_RequestJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of ListSongs_Request. This struct is safe to replace or modify but
// should not be done so concurrently.
var ListSongs_RequestJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *ListSongs_Request) UnmarshalJSON(b []byte) error {
return ListSongs_RequestJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*ListSongs_Request)(nil)
// ListSongs_ResponseJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of ListSongs_ResponseJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var ListSongs_ResponseJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *ListSongs_Response) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := ListSongs_ResponseJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*ListSongs_Response)(nil)
// ListSongs_ResponseJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of ListSongs_Response. This struct is safe to replace or modify but
// should not be done so concurrently.
var ListSongs_ResponseJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *ListSongs_Response) UnmarshalJSON(b []byte) error {
return ListSongs_ResponseJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*ListSongs_Response)(nil)
// ReceiveInsertsJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of ReceiveInsertsJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var ReceiveInsertsJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *ReceiveInserts) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := ReceiveInsertsJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*ReceiveInserts)(nil)
// ReceiveInsertsJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of ReceiveInserts. This struct is safe to replace or modify but
// should not be done so concurrently.
var ReceiveInsertsJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *ReceiveInserts) UnmarshalJSON(b []byte) error {
return ReceiveInsertsJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*ReceiveInserts)(nil)
// ReceiveInserts_RequestJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of ReceiveInserts_RequestJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var ReceiveInserts_RequestJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *ReceiveInserts_Request) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := ReceiveInserts_RequestJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*ReceiveInserts_Request)(nil)
// ReceiveInserts_RequestJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of ReceiveInserts_Request. This struct is safe to replace or modify but
// should not be done so concurrently.
var ReceiveInserts_RequestJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *ReceiveInserts_Request) UnmarshalJSON(b []byte) error {
return ReceiveInserts_RequestJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*ReceiveInserts_Request)(nil)
// EmptyJSONMarshaler describes the default jsonpb.Marshaler used by all
// instances of EmptyJSONMarshaler This struct is safe to replace or modify but
// should not be done so concurrently.
var EmptyJSONMarshaler = new(jsonpb.Marshaler)
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *Empty) MarshalJSON() ([]byte, error) {
if m == nil {
return json.Marshal(nil)
}
buf := &bytes.Buffer{}
if err := EmptyJSONMarshaler.Marshal(buf, m); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
var _ json.Marshaler = (*Empty)(nil)
// EmptyJSONUnmarshaler describes the default jsonpb.Unmarshaler used by all
// instances of Empty. This struct is safe to replace or modify but
// should not be done so concurrently.
var EmptyJSONUnmarshaler = new(jsonpb.Unmarshaler)
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *Empty) UnmarshalJSON(b []byte) error {
return EmptyJSONUnmarshaler.Unmarshal(bytes.NewReader(b), m)
}
var _ json.Unmarshaler = (*Empty)(nil)
type srv struct {
opts *o.Opts
}
type service struct {
tlsCfg *tls.Config
logger *zap.Logger
session *session.Session
UnimplementedExampleServer
}
func New(opts *o.Opts) proxy.Listener {
s := new(srv)
s.opts = opts
return s
}
func NewProxy(opts *o.Opts) proxy.Proxy {
s := New(opts)
p := proxy.New(s, opts)
return p
}
func (s *srv) Start(ctx context.Context, ready func()) func() error {
return func() error {
lis, err := net.Listen("tcp", s.opts.Addr)
if err != nil {
return err
}
ll := s.opts.Logger.With(zap.String("addr", s.opts.Addr))
srv := &service{
session: s.opts.Session,
logger: s.opts.Logger,
}
tlsConfig := &tls.Config{}
tlsConfig.InsecureSkipVerify = true
srv.tlsCfg = tlsConfig
var kaep = keepalive.EnforcementPolicy{
MinTime: 5 * time.Second, // If a client pings more than once every 5 seconds, terminate the connection
PermitWithoutStream: true, // Allow pings even when there are no active streams
}
var kasp = keepalive.ServerParameters{
MaxConnectionIdle: time.Duration(math.MaxInt64), // If a client is idle for 15 seconds, send a GOAWAY
MaxConnectionAge: time.Duration(math.MaxInt64), // If any connection is alive for more than 30 seconds, send a GOAWAY
MaxConnectionAgeGrace: 5 * time.Second, // Allow 5 seconds for pending RPCs to complete before forcibly closing connections
Time: 5 * time.Second, // Ping the client if it is idle for 5 seconds to ensure the connection is still active
Timeout: 1 * time.Second, // Wait 1 second for the ping ack before assuming the connection is dead
}
grpc_zap.ReplaceGrpcLogger(ll)
ss := grpc.NewServer(
grpc.KeepaliveEnforcementPolicy(kaep),
grpc.KeepaliveParams(kasp),
grpc_middleware.WithUnaryServerChain(grpc_zap.UnaryServerInterceptor(ll)))
RegisterExampleServer(ss, srv)
grpc_health_v1.RegisterHealthServer(ss, health.NewServer())
// grpc_health_v1.RegisterHealthServer(ss, srv)
ready()
ll.Info("start listening")
if err := ss.Serve(lis); err != nil {
return err
}
return nil
}
}
// Here goes a message Insert
func (s *service) Insert(ctx context.Context, req *Insert_Request) (*Insert_Response, error) {
b, err := req.MarshalJSON()
if err != nil {
return nil, err
}
svc := lambda.New(s.session)
input := &lambda.InvokeInput{
FunctionName: aws.String("arn:aws:lambda:eu-west-1:291339088935:function:my-test"),
Payload: b,
Qualifier: aws.String("$LATEST"),
}
result, err := svc.InvokeWithContext(ctx, input)
if err != nil {
return nil, err
}
var payload Insert_Response
if err := payload.UnmarshalJSON(result.Payload); err != nil {
return nil, err
}
return &payload, nil
}
// Here goes a message Update
func (s *service) Update(ctx context.Context, req *Update_Request) (*Update_Response, error) {
svc := dynamodb.New(session.New())
input := &dynamodb.UpdateItemInput{
ReturnValues: aws.String("ALL_NEW"),
TableName: aws.String("Music"),
UpdateExpression: aws.String("SET #Y = :y, #AT = :t"),
}
_, err := svc.UpdateItem(input)
if err != nil {
return nil, err
}
// DynamoDB
return nil, nil
}
// Here goes a message ReceiveInserts
func (s *service) ReceiveInserts(req *api.SQS_ReceiveMessageInput, stream Example_ReceiveInsertsServer) error {
queueUrl := req.GetQueueUrl()
svc := sqs.New(s.session)
ll := s.logger.With(zap.String("queue_url", queueUrl))
input := &sqs.ReceiveMessageInput{
QueueUrl: aws.String(queueUrl),
MessageAttributeNames: aws.StringSlice(req.MessageAttributeNames),
MaxNumberOfMessages: aws.Int64(req.MaxNumberOfMessages),
WaitTimeSeconds: aws.Int64(req.WaitTimeSeconds),
}
output, err := svc.ReceiveMessageWithContext(stream.Context(), input)
if err != nil {
return err
}
ll.Info("receiving messages", zap.Int("messages", len(output.Messages)))
receiptHandles := make([]*sqs.DeleteMessageBatchRequestEntry, 0, len(output.Messages))
for _, msg := range output.Messages {
ll.Info("streaming message", zap.String("message_id", aws.StringValue(msg.MessageId)))
m := &api.SQS_Message{
Body: aws.StringValue(msg.Body),
MessageId: aws.StringValue(msg.MessageId),
}
if err := stream.Send(m); err != nil {
ll.Error("sending message", zap.Error(err))
return err
}
receiptHandles = append(receiptHandles, &sqs.DeleteMessageBatchRequestEntry{Id: msg.MessageId, ReceiptHandle: msg.ReceiptHandle})
}
if len(receiptHandles) == 0 {
return nil
}
deleteMessageInput := sqs.DeleteMessageBatchInput{
QueueUrl: aws.String(queueUrl),
Entries: receiptHandles,
}
ll.Info("deleting messages", zap.Int("messages", len(receiptHandles)))
_, err = svc.DeleteMessageBatch(&deleteMessageInput)
if err != nil {
ll.Error("deleting messages", zap.Error(err))
return err
}
return nil
}
// Here goes a message SendInserts
func (s *service) SendInserts(stream Example_SendInsertsServer) error {
svc := sqs.New(s.session)
for {
msg, err := stream.Recv()
if err == io.EOF {
return stream.SendAndClose(&api.Empty{})
}
if err != nil {
return err
}
input := &sqs.SendMessageInput{
QueueUrl: aws.String(msg.GetQueueUrl()),
DelaySeconds: aws.Int64(msg.GetDelaySeconds()),
MessageBody: aws.String(msg.MessageBody),
}
_, err = svc.SendMessage(input)
if err != nil {
return err
}
}
}