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
302 lines (249 loc) · 8.84 KB
/
Copy pathweaver_gen.go
File metadata and controls
302 lines (249 loc) · 8.84 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
// 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: "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: "",
})
}
// weaver.InstanceOf checks.
var _ weaver.InstanceOf[weaver.Main] = (*app)(nil)
var _ weaver.InstanceOf[Searcher] = (*searcher)(nil)
// weaver.Router checks.
var _ weaver.Unrouted = (*app)(nil)
var _ weaver.Unrouted = (*searcher)(nil)
// Local stub implementations.
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 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 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 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
}
// 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
}