This repository was archived by the owner on Jan 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathweaver_gen.go
More file actions
607 lines (508 loc) · 17.6 KB
/
Copy pathweaver_gen.go
File metadata and controls
607 lines (508 loc) · 17.6 KB
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
// Code generated by "weaver generate". DO NOT EDIT.
//go:build !ignoreWeaverGen
package main
import (
"context"
"errors"
"github.com/ServiceWeaver/weaver"
"github.com/ServiceWeaver/weaver/runtime/codegen"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"reflect"
)
func init() {
codegen.Register(codegen.Registration{
Name: "emojis/Cache",
Iface: reflect.TypeOf((*Cache)(nil)).Elem(),
Impl: reflect.TypeOf(cache{}),
Routed: true,
LocalStubFn: func(impl any, caller string, tracer trace.Tracer) any {
return cache_local_stub{impl: impl.(Cache), tracer: tracer, getMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "emojis/Cache", Method: "Get", Remote: false, Generated: true}), putMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "emojis/Cache", Method: "Put", Remote: false, Generated: true})}
},
ClientStubFn: func(stub codegen.Stub, caller string) any {
return cache_client_stub{stub: stub, getMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "emojis/Cache", Method: "Get", Remote: true, Generated: true}), putMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "emojis/Cache", Method: "Put", Remote: true, Generated: true})}
},
ServerStubFn: func(impl any, addLoad func(uint64, float64)) codegen.Server {
return cache_server_stub{impl: impl.(Cache), addLoad: addLoad}
},
ReflectStubFn: func(caller func(string, context.Context, []any, []any) error) any {
return cache_reflect_stub{caller: caller}
},
RefData: "",
})
codegen.Register(codegen.Registration{
Name: "github.com/ServiceWeaver/weaver/Main",
Iface: reflect.TypeOf((*weaver.Main)(nil)).Elem(),
Impl: reflect.TypeOf(app{}),
Listeners: []string{"emojis"},
LocalStubFn: func(impl any, caller string, tracer trace.Tracer) any {
return main_local_stub{impl: impl.(weaver.Main), tracer: tracer}
},
ClientStubFn: func(stub codegen.Stub, caller string) any { return main_client_stub{stub: stub} },
ServerStubFn: func(impl any, addLoad func(uint64, float64)) codegen.Server {
return main_server_stub{impl: impl.(weaver.Main), addLoad: addLoad}
},
ReflectStubFn: func(caller func(string, context.Context, []any, []any) error) any {
return main_reflect_stub{caller: caller}
},
RefData: "⟦f3377ce6:wEaVeReDgE:github.com/ServiceWeaver/weaver/Main→emojis/Searcher⟧\n⟦a234aa48:wEaVeRlIsTeNeRs:github.com/ServiceWeaver/weaver/Main→emojis⟧\n",
})
codegen.Register(codegen.Registration{
Name: "emojis/Searcher",
Iface: reflect.TypeOf((*Searcher)(nil)).Elem(),
Impl: reflect.TypeOf(searcher{}),
LocalStubFn: func(impl any, caller string, tracer trace.Tracer) any {
return searcher_local_stub{impl: impl.(Searcher), tracer: tracer, searchMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "emojis/Searcher", Method: "Search", Remote: false, Generated: true})}
},
ClientStubFn: func(stub codegen.Stub, caller string) any {
return searcher_client_stub{stub: stub, searchMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "emojis/Searcher", Method: "Search", Remote: true, Generated: true})}
},
ServerStubFn: func(impl any, addLoad func(uint64, float64)) codegen.Server {
return searcher_server_stub{impl: impl.(Searcher), addLoad: addLoad}
},
ReflectStubFn: func(caller func(string, context.Context, []any, []any) error) any {
return searcher_reflect_stub{caller: caller}
},
RefData: "⟦e0ea07ba:wEaVeReDgE:emojis/Searcher→emojis/Cache⟧\n",
})
}
// weaver.InstanceOf checks.
var _ weaver.InstanceOf[Cache] = (*cache)(nil)
var _ weaver.InstanceOf[weaver.Main] = (*app)(nil)
var _ weaver.InstanceOf[Searcher] = (*searcher)(nil)
// weaver.Router checks.
var _ weaver.RoutedBy[router] = (*cache)(nil)
var _ weaver.Unrouted = (*app)(nil)
var _ weaver.Unrouted = (*searcher)(nil)
// Component "cache", router "router" checks.
var _ func(_ context.Context, query string) string = (&router{}).Get // routed
var _ func(_ context.Context, query string, _ []string) string = (&router{}).Put // routed
// Local stub implementations.
type cache_local_stub struct {
impl Cache
tracer trace.Tracer
getMetrics *codegen.MethodMetrics
putMetrics *codegen.MethodMetrics
}
// Check that cache_local_stub implements the Cache interface.
var _ Cache = (*cache_local_stub)(nil)
func (s cache_local_stub) Get(ctx context.Context, a0 string) (r0 []string, err error) {
// Update metrics.
begin := s.getMetrics.Begin()
defer func() { s.getMetrics.End(begin, err != nil, 0, 0) }()
span := trace.SpanFromContext(ctx)
if span.SpanContext().IsValid() {
// Create a child span for this method.
ctx, span = s.tracer.Start(ctx, "main.Cache.Get", trace.WithSpanKind(trace.SpanKindInternal))
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
}
return s.impl.Get(ctx, a0)
}
func (s cache_local_stub) Put(ctx context.Context, a0 string, a1 []string) (err error) {
// Update metrics.
begin := s.putMetrics.Begin()
defer func() { s.putMetrics.End(begin, err != nil, 0, 0) }()
span := trace.SpanFromContext(ctx)
if span.SpanContext().IsValid() {
// Create a child span for this method.
ctx, span = s.tracer.Start(ctx, "main.Cache.Put", trace.WithSpanKind(trace.SpanKindInternal))
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
}
return s.impl.Put(ctx, a0, a1)
}
type main_local_stub struct {
impl weaver.Main
tracer trace.Tracer
}
// Check that main_local_stub implements the weaver.Main interface.
var _ weaver.Main = (*main_local_stub)(nil)
type searcher_local_stub struct {
impl Searcher
tracer trace.Tracer
searchMetrics *codegen.MethodMetrics
}
// Check that searcher_local_stub implements the Searcher interface.
var _ Searcher = (*searcher_local_stub)(nil)
func (s searcher_local_stub) Search(ctx context.Context, a0 string) (r0 []string, err error) {
// Update metrics.
begin := s.searchMetrics.Begin()
defer func() { s.searchMetrics.End(begin, err != nil, 0, 0) }()
span := trace.SpanFromContext(ctx)
if span.SpanContext().IsValid() {
// Create a child span for this method.
ctx, span = s.tracer.Start(ctx, "main.Searcher.Search", trace.WithSpanKind(trace.SpanKindInternal))
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
}
return s.impl.Search(ctx, a0)
}
// Client stub implementations.
type cache_client_stub struct {
stub codegen.Stub
getMetrics *codegen.MethodMetrics
putMetrics *codegen.MethodMetrics
}
// Check that cache_client_stub implements the Cache interface.
var _ Cache = (*cache_client_stub)(nil)
func (s cache_client_stub) Get(ctx context.Context, a0 string) (r0 []string, err error) {
// Update metrics.
var requestBytes, replyBytes int
begin := s.getMetrics.Begin()
defer func() { s.getMetrics.End(begin, err != nil, requestBytes, replyBytes) }()
span := trace.SpanFromContext(ctx)
if span.SpanContext().IsValid() {
// Create a child span for this method.
ctx, span = s.stub.Tracer().Start(ctx, "main.Cache.Get", trace.WithSpanKind(trace.SpanKindClient))
}
defer func() {
// Catch and return any panics detected during encoding/decoding/rpc.
if err == nil {
err = codegen.CatchPanics(recover())
if err != nil {
err = errors.Join(weaver.RemoteCallError, err)
}
}
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
// Preallocate a buffer of the right size.
size := 0
size += (4 + len(a0))
enc := codegen.NewEncoder()
enc.Reset(size)
// Encode arguments.
enc.String(a0)
// Set the shardKey.
var r router
shardKey := _hashCache(r.Get(ctx, a0))
// Call the remote method.
requestBytes = len(enc.Data())
var results []byte
results, err = s.stub.Run(ctx, 0, enc.Data(), shardKey)
replyBytes = len(results)
if err != nil {
err = errors.Join(weaver.RemoteCallError, err)
return
}
// Decode the results.
dec := codegen.NewDecoder(results)
r0 = serviceweaver_dec_slice_string_4af10117(dec)
err = dec.Error()
return
}
func (s cache_client_stub) Put(ctx context.Context, a0 string, a1 []string) (err error) {
// Update metrics.
var requestBytes, replyBytes int
begin := s.putMetrics.Begin()
defer func() { s.putMetrics.End(begin, err != nil, requestBytes, replyBytes) }()
span := trace.SpanFromContext(ctx)
if span.SpanContext().IsValid() {
// Create a child span for this method.
ctx, span = s.stub.Tracer().Start(ctx, "main.Cache.Put", trace.WithSpanKind(trace.SpanKindClient))
}
defer func() {
// Catch and return any panics detected during encoding/decoding/rpc.
if err == nil {
err = codegen.CatchPanics(recover())
if err != nil {
err = errors.Join(weaver.RemoteCallError, err)
}
}
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
// Encode arguments.
enc := codegen.NewEncoder()
enc.String(a0)
serviceweaver_enc_slice_string_4af10117(enc, a1)
// Set the shardKey.
var r router
shardKey := _hashCache(r.Put(ctx, a0, a1))
// Call the remote method.
requestBytes = len(enc.Data())
var results []byte
results, err = s.stub.Run(ctx, 1, enc.Data(), shardKey)
replyBytes = len(results)
if err != nil {
err = errors.Join(weaver.RemoteCallError, err)
return
}
// Decode the results.
dec := codegen.NewDecoder(results)
err = dec.Error()
return
}
type main_client_stub struct {
stub codegen.Stub
}
// Check that main_client_stub implements the weaver.Main interface.
var _ weaver.Main = (*main_client_stub)(nil)
type searcher_client_stub struct {
stub codegen.Stub
searchMetrics *codegen.MethodMetrics
}
// Check that searcher_client_stub implements the Searcher interface.
var _ Searcher = (*searcher_client_stub)(nil)
func (s searcher_client_stub) Search(ctx context.Context, a0 string) (r0 []string, err error) {
// Update metrics.
var requestBytes, replyBytes int
begin := s.searchMetrics.Begin()
defer func() { s.searchMetrics.End(begin, err != nil, requestBytes, replyBytes) }()
span := trace.SpanFromContext(ctx)
if span.SpanContext().IsValid() {
// Create a child span for this method.
ctx, span = s.stub.Tracer().Start(ctx, "main.Searcher.Search", trace.WithSpanKind(trace.SpanKindClient))
}
defer func() {
// Catch and return any panics detected during encoding/decoding/rpc.
if err == nil {
err = codegen.CatchPanics(recover())
if err != nil {
err = errors.Join(weaver.RemoteCallError, err)
}
}
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
// Preallocate a buffer of the right size.
size := 0
size += (4 + len(a0))
enc := codegen.NewEncoder()
enc.Reset(size)
// Encode arguments.
enc.String(a0)
var shardKey uint64
// Call the remote method.
requestBytes = len(enc.Data())
var results []byte
results, err = s.stub.Run(ctx, 0, enc.Data(), shardKey)
replyBytes = len(results)
if err != nil {
err = errors.Join(weaver.RemoteCallError, err)
return
}
// Decode the results.
dec := codegen.NewDecoder(results)
r0 = serviceweaver_dec_slice_string_4af10117(dec)
err = dec.Error()
return
}
// Note that "weaver generate" will always generate the error message below.
// Everything is okay. The error message is only relevant if you see it when
// you run "go build" or "go run".
var _ codegen.LatestVersion = codegen.Version[[0][24]struct{}](`
ERROR: You generated this file with 'weaver generate' v0.24.6 (codegen
version v0.24.0). The generated code is incompatible with the version of the
github.com/ServiceWeaver/weaver module that you're using. The weaver module
version can be found in your go.mod file or by running the following command.
go list -m github.com/ServiceWeaver/weaver
We recommend updating the weaver module and the 'weaver generate' command by
running the following.
go get github.com/ServiceWeaver/weaver@latest
go install github.com/ServiceWeaver/weaver/cmd/weaver@latest
Then, re-run 'weaver generate' and re-build your code. If the problem persists,
please file an issue at https://github.com/ServiceWeaver/weaver/issues.
`)
// Server stub implementations.
type cache_server_stub struct {
impl Cache
addLoad func(key uint64, load float64)
}
// Check that cache_server_stub implements the codegen.Server interface.
var _ codegen.Server = (*cache_server_stub)(nil)
// GetStubFn implements the codegen.Server interface.
func (s cache_server_stub) GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) {
switch method {
case "Get":
return s.get
case "Put":
return s.put
default:
return nil
}
}
func (s cache_server_stub) get(ctx context.Context, args []byte) (res []byte, err error) {
// Catch and return any panics detected during encoding/decoding/rpc.
defer func() {
if err == nil {
err = codegen.CatchPanics(recover())
}
}()
// Decode arguments.
dec := codegen.NewDecoder(args)
var a0 string
a0 = dec.String()
var r router
s.addLoad(_hashCache(r.Get(ctx, a0)), 1.0)
// TODO(rgrandl): The deferred function above will recover from panics in the
// user code: fix this.
// Call the local method.
r0, appErr := s.impl.Get(ctx, a0)
// Encode the results.
enc := codegen.NewEncoder()
serviceweaver_enc_slice_string_4af10117(enc, r0)
enc.Error(appErr)
return enc.Data(), nil
}
func (s cache_server_stub) put(ctx context.Context, args []byte) (res []byte, err error) {
// Catch and return any panics detected during encoding/decoding/rpc.
defer func() {
if err == nil {
err = codegen.CatchPanics(recover())
}
}()
// Decode arguments.
dec := codegen.NewDecoder(args)
var a0 string
a0 = dec.String()
var a1 []string
a1 = serviceweaver_dec_slice_string_4af10117(dec)
var r router
s.addLoad(_hashCache(r.Put(ctx, a0, a1)), 1.0)
// TODO(rgrandl): The deferred function above will recover from panics in the
// user code: fix this.
// Call the local method.
appErr := s.impl.Put(ctx, a0, a1)
// Encode the results.
enc := codegen.NewEncoder()
enc.Error(appErr)
return enc.Data(), nil
}
type main_server_stub struct {
impl weaver.Main
addLoad func(key uint64, load float64)
}
// Check that main_server_stub implements the codegen.Server interface.
var _ codegen.Server = (*main_server_stub)(nil)
// GetStubFn implements the codegen.Server interface.
func (s main_server_stub) GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) {
switch method {
default:
return nil
}
}
type searcher_server_stub struct {
impl Searcher
addLoad func(key uint64, load float64)
}
// Check that searcher_server_stub implements the codegen.Server interface.
var _ codegen.Server = (*searcher_server_stub)(nil)
// GetStubFn implements the codegen.Server interface.
func (s searcher_server_stub) GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) {
switch method {
case "Search":
return s.search
default:
return nil
}
}
func (s searcher_server_stub) search(ctx context.Context, args []byte) (res []byte, err error) {
// Catch and return any panics detected during encoding/decoding/rpc.
defer func() {
if err == nil {
err = codegen.CatchPanics(recover())
}
}()
// Decode arguments.
dec := codegen.NewDecoder(args)
var a0 string
a0 = dec.String()
// TODO(rgrandl): The deferred function above will recover from panics in the
// user code: fix this.
// Call the local method.
r0, appErr := s.impl.Search(ctx, a0)
// Encode the results.
enc := codegen.NewEncoder()
serviceweaver_enc_slice_string_4af10117(enc, r0)
enc.Error(appErr)
return enc.Data(), nil
}
// Reflect stub implementations.
type cache_reflect_stub struct {
caller func(string, context.Context, []any, []any) error
}
// Check that cache_reflect_stub implements the Cache interface.
var _ Cache = (*cache_reflect_stub)(nil)
func (s cache_reflect_stub) Get(ctx context.Context, a0 string) (r0 []string, err error) {
err = s.caller("Get", ctx, []any{a0}, []any{&r0})
return
}
func (s cache_reflect_stub) Put(ctx context.Context, a0 string, a1 []string) (err error) {
err = s.caller("Put", ctx, []any{a0, a1}, []any{})
return
}
type main_reflect_stub struct {
caller func(string, context.Context, []any, []any) error
}
// Check that main_reflect_stub implements the weaver.Main interface.
var _ weaver.Main = (*main_reflect_stub)(nil)
type searcher_reflect_stub struct {
caller func(string, context.Context, []any, []any) error
}
// Check that searcher_reflect_stub implements the Searcher interface.
var _ Searcher = (*searcher_reflect_stub)(nil)
func (s searcher_reflect_stub) Search(ctx context.Context, a0 string) (r0 []string, err error) {
err = s.caller("Search", ctx, []any{a0}, []any{&r0})
return
}
// Router methods.
// _hashCache returns a 64 bit hash of the provided value.
func _hashCache(r string) uint64 {
var h codegen.Hasher
h.WriteString(string(r))
return h.Sum64()
}
// _orderedCodeCache returns an order-preserving serialization of the provided value.
func _orderedCodeCache(r string) codegen.OrderedCode {
var enc codegen.OrderedEncoder
enc.WriteString(string(r))
return enc.Encode()
}
// Encoding/decoding implementations.
func serviceweaver_enc_slice_string_4af10117(enc *codegen.Encoder, arg []string) {
if arg == nil {
enc.Len(-1)
return
}
enc.Len(len(arg))
for i := 0; i < len(arg); i++ {
enc.String(arg[i])
}
}
func serviceweaver_dec_slice_string_4af10117(dec *codegen.Decoder) []string {
n := dec.Len()
if n == -1 {
return nil
}
res := make([]string, n)
for i := 0; i < n; i++ {
res[i] = dec.String()
}
return res
}