-
Notifications
You must be signed in to change notification settings - Fork 219
/
weaver_gen.go
384 lines (318 loc) · 11.5 KB
/
weaver_gen.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
// Code generated by "weaver generate". DO NOT EDIT.
//go:build !ignoreWeaverGen
package deploy
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: "github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Started",
Iface: reflect.TypeOf((*Started)(nil)).Elem(),
Impl: reflect.TypeOf(started{}),
LocalStubFn: func(impl any, caller string, tracer trace.Tracer) any {
return started_local_stub{impl: impl.(Started), tracer: tracer, markStartedMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Started", Method: "MarkStarted", Remote: false, Generated: true})}
},
ClientStubFn: func(stub codegen.Stub, caller string) any {
return started_client_stub{stub: stub, markStartedMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Started", Method: "MarkStarted", Remote: true, Generated: true})}
},
ServerStubFn: func(impl any, addLoad func(uint64, float64)) codegen.Server {
return started_server_stub{impl: impl.(Started), addLoad: addLoad}
},
ReflectStubFn: func(caller func(string, context.Context, []any, []any) error) any {
return started_reflect_stub{caller: caller}
},
RefData: "",
})
codegen.Register(codegen.Registration{
Name: "github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Widget",
Iface: reflect.TypeOf((*Widget)(nil)).Elem(),
Impl: reflect.TypeOf(widget{}),
LocalStubFn: func(impl any, caller string, tracer trace.Tracer) any {
return widget_local_stub{impl: impl.(Widget), tracer: tracer, useMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Widget", Method: "Use", Remote: false, Generated: true})}
},
ClientStubFn: func(stub codegen.Stub, caller string) any {
return widget_client_stub{stub: stub, useMetrics: codegen.MethodMetricsFor(codegen.MethodLabels{Caller: caller, Component: "github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Widget", Method: "Use", Remote: true, Generated: true})}
},
ServerStubFn: func(impl any, addLoad func(uint64, float64)) codegen.Server {
return widget_server_stub{impl: impl.(Widget), addLoad: addLoad}
},
ReflectStubFn: func(caller func(string, context.Context, []any, []any) error) any {
return widget_reflect_stub{caller: caller}
},
RefData: "⟦f3fa3c18:wEaVeReDgE:github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Widget→github.com/ServiceWeaver/weaver/weavertest/internal/deploy/Started⟧\n",
})
}
// weaver.InstanceOf checks.
var _ weaver.InstanceOf[Started] = (*started)(nil)
var _ weaver.InstanceOf[Widget] = (*widget)(nil)
// weaver.Router checks.
var _ weaver.Unrouted = (*started)(nil)
var _ weaver.Unrouted = (*widget)(nil)
// Local stub implementations.
type started_local_stub struct {
impl Started
tracer trace.Tracer
markStartedMetrics *codegen.MethodMetrics
}
// Check that started_local_stub implements the Started interface.
var _ Started = (*started_local_stub)(nil)
func (s started_local_stub) MarkStarted(ctx context.Context, a0 string) (err error) {
// Update metrics.
begin := s.markStartedMetrics.Begin()
defer func() { s.markStartedMetrics.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, "deploy.Started.MarkStarted", trace.WithSpanKind(trace.SpanKindInternal))
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
}
return s.impl.MarkStarted(ctx, a0)
}
type widget_local_stub struct {
impl Widget
tracer trace.Tracer
useMetrics *codegen.MethodMetrics
}
// Check that widget_local_stub implements the Widget interface.
var _ Widget = (*widget_local_stub)(nil)
func (s widget_local_stub) Use(ctx context.Context, a0 string) (err error) {
// Update metrics.
begin := s.useMetrics.Begin()
defer func() { s.useMetrics.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, "deploy.Widget.Use", trace.WithSpanKind(trace.SpanKindInternal))
defer func() {
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
}
span.End()
}()
}
return s.impl.Use(ctx, a0)
}
// Client stub implementations.
type started_client_stub struct {
stub codegen.Stub
markStartedMetrics *codegen.MethodMetrics
}
// Check that started_client_stub implements the Started interface.
var _ Started = (*started_client_stub)(nil)
func (s started_client_stub) MarkStarted(ctx context.Context, a0 string) (err error) {
// Update metrics.
var requestBytes, replyBytes int
begin := s.markStartedMetrics.Begin()
defer func() { s.markStartedMetrics.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, "deploy.Started.MarkStarted", 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)
err = dec.Error()
return
}
type widget_client_stub struct {
stub codegen.Stub
useMetrics *codegen.MethodMetrics
}
// Check that widget_client_stub implements the Widget interface.
var _ Widget = (*widget_client_stub)(nil)
func (s widget_client_stub) Use(ctx context.Context, a0 string) (err error) {
// Update metrics.
var requestBytes, replyBytes int
begin := s.useMetrics.Begin()
defer func() { s.useMetrics.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, "deploy.Widget.Use", 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)
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' (devel) (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 started_server_stub struct {
impl Started
addLoad func(key uint64, load float64)
}
// Check that started_server_stub implements the codegen.Server interface.
var _ codegen.Server = (*started_server_stub)(nil)
// GetStubFn implements the codegen.Server interface.
func (s started_server_stub) GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) {
switch method {
case "MarkStarted":
return s.markStarted
default:
return nil
}
}
func (s started_server_stub) markStarted(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.
appErr := s.impl.MarkStarted(ctx, a0)
// Encode the results.
enc := codegen.NewEncoder()
enc.Error(appErr)
return enc.Data(), nil
}
type widget_server_stub struct {
impl Widget
addLoad func(key uint64, load float64)
}
// Check that widget_server_stub implements the codegen.Server interface.
var _ codegen.Server = (*widget_server_stub)(nil)
// GetStubFn implements the codegen.Server interface.
func (s widget_server_stub) GetStubFn(method string) func(ctx context.Context, args []byte) ([]byte, error) {
switch method {
case "Use":
return s.use
default:
return nil
}
}
func (s widget_server_stub) use(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.
appErr := s.impl.Use(ctx, a0)
// Encode the results.
enc := codegen.NewEncoder()
enc.Error(appErr)
return enc.Data(), nil
}
// Reflect stub implementations.
type started_reflect_stub struct {
caller func(string, context.Context, []any, []any) error
}
// Check that started_reflect_stub implements the Started interface.
var _ Started = (*started_reflect_stub)(nil)
func (s started_reflect_stub) MarkStarted(ctx context.Context, a0 string) (err error) {
err = s.caller("MarkStarted", ctx, []any{a0}, []any{})
return
}
type widget_reflect_stub struct {
caller func(string, context.Context, []any, []any) error
}
// Check that widget_reflect_stub implements the Widget interface.
var _ Widget = (*widget_reflect_stub)(nil)
func (s widget_reflect_stub) Use(ctx context.Context, a0 string) (err error) {
err = s.caller("Use", ctx, []any{a0}, []any{})
return
}