-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.pb.fieldpath.go
508 lines (447 loc) · 15.6 KB
/
status.pb.fieldpath.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
// Code generated by protoc-gen-goten-object
// File: edgelq/common/rpc/status.proto
// DO NOT EDIT!!!
package rpc
import (
"encoding/json"
"fmt"
"reflect"
"strings"
"time"
"github.com/iancoleman/strcase"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/types/known/fieldmaskpb"
gotenobject "github.com/cloudwan/goten-sdk/runtime/object"
)
// proto imports
import (
any "github.com/golang/protobuf/ptypes/any"
)
// ensure the imports are used
var (
_ = json.Marshaler(nil)
_ = fmt.Stringer(nil)
_ = reflect.DeepEqual
_ = strings.Builder{}
_ = time.Second
_ = strcase.ToLowerCamel
_ = codes.NotFound
_ = status.Status{}
_ = protojson.UnmarshalOptions{}
_ = proto.Message(nil)
_ = protoregistry.GlobalTypes
_ = fieldmaskpb.FieldMask{}
_ = gotenobject.FieldPath(nil)
)
// make sure we're using proto imports
var (
_ = &any.Any{}
)
// FieldPath provides implementation to handle
// https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/field_mask.proto
type Status_FieldPath interface {
gotenobject.FieldPath
Selector() Status_FieldPathSelector
Get(source *Status) []interface{}
GetSingle(source *Status) (interface{}, bool)
ClearValue(item *Status)
// Those methods build corresponding Status_FieldPathValue
// (or array of values) and holds passed value. Panics if injected type is incorrect.
WithIValue(value interface{}) Status_FieldPathValue
WithIArrayOfValues(values interface{}) Status_FieldPathArrayOfValues
WithIArrayItemValue(value interface{}) Status_FieldPathArrayItemValue
}
type Status_FieldPathSelector int32
const (
Status_FieldPathSelectorCode Status_FieldPathSelector = 0
Status_FieldPathSelectorMessage Status_FieldPathSelector = 1
Status_FieldPathSelectorDetails Status_FieldPathSelector = 2
)
func (s Status_FieldPathSelector) String() string {
switch s {
case Status_FieldPathSelectorCode:
return "code"
case Status_FieldPathSelectorMessage:
return "message"
case Status_FieldPathSelectorDetails:
return "details"
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", s))
}
}
func BuildStatus_FieldPath(fp gotenobject.RawFieldPath) (Status_FieldPath, error) {
if len(fp) == 0 {
return nil, status.Error(codes.InvalidArgument, "empty field path for object Status")
}
if len(fp) == 1 {
switch fp[0] {
case "code":
return &Status_FieldTerminalPath{selector: Status_FieldPathSelectorCode}, nil
case "message":
return &Status_FieldTerminalPath{selector: Status_FieldPathSelectorMessage}, nil
case "details":
return &Status_FieldTerminalPath{selector: Status_FieldPathSelectorDetails}, nil
}
}
return nil, status.Errorf(codes.InvalidArgument, "unknown field path '%s' for object Status", fp)
}
func ParseStatus_FieldPath(rawField string) (Status_FieldPath, error) {
fp, err := gotenobject.ParseRawFieldPath(rawField)
if err != nil {
return nil, err
}
return BuildStatus_FieldPath(fp)
}
func MustParseStatus_FieldPath(rawField string) Status_FieldPath {
fp, err := ParseStatus_FieldPath(rawField)
if err != nil {
panic(err)
}
return fp
}
type Status_FieldTerminalPath struct {
selector Status_FieldPathSelector
}
var _ Status_FieldPath = (*Status_FieldTerminalPath)(nil)
func (fp *Status_FieldTerminalPath) Selector() Status_FieldPathSelector {
return fp.selector
}
// String returns path representation in proto convention
func (fp *Status_FieldTerminalPath) String() string {
return fp.selector.String()
}
// JSONString returns path representation is JSON convention
func (fp *Status_FieldTerminalPath) JSONString() string {
return strcase.ToLowerCamel(fp.String())
}
// Get returns all values pointed by specific field from source Status
func (fp *Status_FieldTerminalPath) Get(source *Status) (values []interface{}) {
if source != nil {
switch fp.selector {
case Status_FieldPathSelectorCode:
values = append(values, source.Code)
case Status_FieldPathSelectorMessage:
values = append(values, source.Message)
case Status_FieldPathSelectorDetails:
for _, value := range source.GetDetails() {
values = append(values, value)
}
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fp.selector))
}
}
return
}
func (fp *Status_FieldTerminalPath) GetRaw(source proto.Message) []interface{} {
return fp.Get(source.(*Status))
}
// GetSingle returns value pointed by specific field of from source Status
func (fp *Status_FieldTerminalPath) GetSingle(source *Status) (interface{}, bool) {
switch fp.selector {
case Status_FieldPathSelectorCode:
return source.GetCode(), source != nil
case Status_FieldPathSelectorMessage:
return source.GetMessage(), source != nil
case Status_FieldPathSelectorDetails:
res := source.GetDetails()
return res, res != nil
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fp.selector))
}
}
func (fp *Status_FieldTerminalPath) GetSingleRaw(source proto.Message) (interface{}, bool) {
return fp.GetSingle(source.(*Status))
}
// GetDefault returns a default value of the field type
func (fp *Status_FieldTerminalPath) GetDefault() interface{} {
switch fp.selector {
case Status_FieldPathSelectorCode:
return int32(0)
case Status_FieldPathSelectorMessage:
return ""
case Status_FieldPathSelectorDetails:
return ([]*any.Any)(nil)
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fp.selector))
}
}
func (fp *Status_FieldTerminalPath) ClearValue(item *Status) {
if item != nil {
switch fp.selector {
case Status_FieldPathSelectorCode:
item.Code = int32(0)
case Status_FieldPathSelectorMessage:
item.Message = ""
case Status_FieldPathSelectorDetails:
item.Details = nil
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fp.selector))
}
}
}
func (fp *Status_FieldTerminalPath) ClearValueRaw(item proto.Message) {
fp.ClearValue(item.(*Status))
}
// IsLeaf - whether field path is holds simple value
func (fp *Status_FieldTerminalPath) IsLeaf() bool {
return fp.selector == Status_FieldPathSelectorCode ||
fp.selector == Status_FieldPathSelectorMessage ||
fp.selector == Status_FieldPathSelectorDetails
}
func (fp *Status_FieldTerminalPath) WithIValue(value interface{}) Status_FieldPathValue {
switch fp.selector {
case Status_FieldPathSelectorCode:
return &Status_FieldTerminalPathValue{Status_FieldTerminalPath: *fp, value: value.(int32)}
case Status_FieldPathSelectorMessage:
return &Status_FieldTerminalPathValue{Status_FieldTerminalPath: *fp, value: value.(string)}
case Status_FieldPathSelectorDetails:
return &Status_FieldTerminalPathValue{Status_FieldTerminalPath: *fp, value: value.([]*any.Any)}
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fp.selector))
}
}
func (fp *Status_FieldTerminalPath) WithRawIValue(value interface{}) gotenobject.FieldPathValue {
return fp.WithIValue(value)
}
func (fp *Status_FieldTerminalPath) WithIArrayOfValues(values interface{}) Status_FieldPathArrayOfValues {
fpaov := &Status_FieldTerminalPathArrayOfValues{Status_FieldTerminalPath: *fp}
switch fp.selector {
case Status_FieldPathSelectorCode:
return &Status_FieldTerminalPathArrayOfValues{Status_FieldTerminalPath: *fp, values: values.([]int32)}
case Status_FieldPathSelectorMessage:
return &Status_FieldTerminalPathArrayOfValues{Status_FieldTerminalPath: *fp, values: values.([]string)}
case Status_FieldPathSelectorDetails:
return &Status_FieldTerminalPathArrayOfValues{Status_FieldTerminalPath: *fp, values: values.([][]*any.Any)}
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fp.selector))
}
return fpaov
}
func (fp *Status_FieldTerminalPath) WithRawIArrayOfValues(values interface{}) gotenobject.FieldPathArrayOfValues {
return fp.WithIArrayOfValues(values)
}
func (fp *Status_FieldTerminalPath) WithIArrayItemValue(value interface{}) Status_FieldPathArrayItemValue {
switch fp.selector {
case Status_FieldPathSelectorDetails:
return &Status_FieldTerminalPathArrayItemValue{Status_FieldTerminalPath: *fp, value: value.(*any.Any)}
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fp.selector))
}
}
func (fp *Status_FieldTerminalPath) WithRawIArrayItemValue(value interface{}) gotenobject.FieldPathArrayItemValue {
return fp.WithIArrayItemValue(value)
}
// Status_FieldPathValue allows storing values for Status fields according to their type
type Status_FieldPathValue interface {
Status_FieldPath
gotenobject.FieldPathValue
SetTo(target **Status)
CompareWith(*Status) (cmp int, comparable bool)
}
func ParseStatus_FieldPathValue(pathStr, valueStr string) (Status_FieldPathValue, error) {
fp, err := ParseStatus_FieldPath(pathStr)
if err != nil {
return nil, err
}
fpv, err := gotenobject.ParseFieldPathValue(fp, valueStr)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error parsing Status field path value from %s: %v", valueStr, err)
}
return fpv.(Status_FieldPathValue), nil
}
func MustParseStatus_FieldPathValue(pathStr, valueStr string) Status_FieldPathValue {
fpv, err := ParseStatus_FieldPathValue(pathStr, valueStr)
if err != nil {
panic(err)
}
return fpv
}
type Status_FieldTerminalPathValue struct {
Status_FieldTerminalPath
value interface{}
}
var _ Status_FieldPathValue = (*Status_FieldTerminalPathValue)(nil)
// GetRawValue returns raw value stored under selected path for 'Status' as interface{}
func (fpv *Status_FieldTerminalPathValue) GetRawValue() interface{} {
return fpv.value
}
func (fpv *Status_FieldTerminalPathValue) AsCodeValue() (int32, bool) {
res, ok := fpv.value.(int32)
return res, ok
}
func (fpv *Status_FieldTerminalPathValue) AsMessageValue() (string, bool) {
res, ok := fpv.value.(string)
return res, ok
}
func (fpv *Status_FieldTerminalPathValue) AsDetailsValue() ([]*any.Any, bool) {
res, ok := fpv.value.([]*any.Any)
return res, ok
}
// SetTo stores value for selected field for object Status
func (fpv *Status_FieldTerminalPathValue) SetTo(target **Status) {
if *target == nil {
*target = new(Status)
}
switch fpv.selector {
case Status_FieldPathSelectorCode:
(*target).Code = fpv.value.(int32)
case Status_FieldPathSelectorMessage:
(*target).Message = fpv.value.(string)
case Status_FieldPathSelectorDetails:
(*target).Details = fpv.value.([]*any.Any)
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fpv.selector))
}
}
func (fpv *Status_FieldTerminalPathValue) SetToRaw(target proto.Message) {
typedObject := target.(*Status)
fpv.SetTo(&typedObject)
}
// CompareWith compares value in the 'Status_FieldTerminalPathValue' with the value under path in 'Status'.
func (fpv *Status_FieldTerminalPathValue) CompareWith(source *Status) (int, bool) {
switch fpv.selector {
case Status_FieldPathSelectorCode:
leftValue := fpv.value.(int32)
rightValue := source.GetCode()
if (leftValue) == (rightValue) {
return 0, true
} else if (leftValue) < (rightValue) {
return -1, true
} else {
return 1, true
}
case Status_FieldPathSelectorMessage:
leftValue := fpv.value.(string)
rightValue := source.GetMessage()
if (leftValue) == (rightValue) {
return 0, true
} else if (leftValue) < (rightValue) {
return -1, true
} else {
return 1, true
}
case Status_FieldPathSelectorDetails:
return 0, false
default:
panic(fmt.Sprintf("Invalid selector for Status: %d", fpv.selector))
}
}
func (fpv *Status_FieldTerminalPathValue) CompareWithRaw(source proto.Message) (int, bool) {
return fpv.CompareWith(source.(*Status))
}
// Status_FieldPathArrayItemValue allows storing single item in Path-specific values for Status according to their type
// Present only for array (repeated) types.
type Status_FieldPathArrayItemValue interface {
gotenobject.FieldPathArrayItemValue
Status_FieldPath
ContainsValue(*Status) bool
}
// ParseStatus_FieldPathArrayItemValue parses string and JSON-encoded value to its Value
func ParseStatus_FieldPathArrayItemValue(pathStr, valueStr string) (Status_FieldPathArrayItemValue, error) {
fp, err := ParseStatus_FieldPath(pathStr)
if err != nil {
return nil, err
}
fpaiv, err := gotenobject.ParseFieldPathArrayItemValue(fp, valueStr)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error parsing Status field path array item value from %s: %v", valueStr, err)
}
return fpaiv.(Status_FieldPathArrayItemValue), nil
}
func MustParseStatus_FieldPathArrayItemValue(pathStr, valueStr string) Status_FieldPathArrayItemValue {
fpaiv, err := ParseStatus_FieldPathArrayItemValue(pathStr, valueStr)
if err != nil {
panic(err)
}
return fpaiv
}
type Status_FieldTerminalPathArrayItemValue struct {
Status_FieldTerminalPath
value interface{}
}
var _ Status_FieldPathArrayItemValue = (*Status_FieldTerminalPathArrayItemValue)(nil)
// GetRawValue returns stored element value for array in object Status as interface{}
func (fpaiv *Status_FieldTerminalPathArrayItemValue) GetRawItemValue() interface{} {
return fpaiv.value
}
func (fpaiv *Status_FieldTerminalPathArrayItemValue) AsDetailsItemValue() (*any.Any, bool) {
res, ok := fpaiv.value.(*any.Any)
return res, ok
}
func (fpaiv *Status_FieldTerminalPathArrayItemValue) GetSingle(source *Status) (interface{}, bool) {
return nil, false
}
func (fpaiv *Status_FieldTerminalPathArrayItemValue) GetSingleRaw(source proto.Message) (interface{}, bool) {
return fpaiv.GetSingle(source.(*Status))
}
// Contains returns a boolean indicating if value that is being held is present in given 'Status'
func (fpaiv *Status_FieldTerminalPathArrayItemValue) ContainsValue(source *Status) bool {
slice := fpaiv.Status_FieldTerminalPath.Get(source)
for _, v := range slice {
if reflect.DeepEqual(v, fpaiv.value) {
return true
}
}
return false
}
// Status_FieldPathArrayOfValues allows storing slice of values for Status fields according to their type
type Status_FieldPathArrayOfValues interface {
gotenobject.FieldPathArrayOfValues
Status_FieldPath
}
func ParseStatus_FieldPathArrayOfValues(pathStr, valuesStr string) (Status_FieldPathArrayOfValues, error) {
fp, err := ParseStatus_FieldPath(pathStr)
if err != nil {
return nil, err
}
fpaov, err := gotenobject.ParseFieldPathArrayOfValues(fp, valuesStr)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error parsing Status field path array of values from %s: %v", valuesStr, err)
}
return fpaov.(Status_FieldPathArrayOfValues), nil
}
func MustParseStatus_FieldPathArrayOfValues(pathStr, valuesStr string) Status_FieldPathArrayOfValues {
fpaov, err := ParseStatus_FieldPathArrayOfValues(pathStr, valuesStr)
if err != nil {
panic(err)
}
return fpaov
}
type Status_FieldTerminalPathArrayOfValues struct {
Status_FieldTerminalPath
values interface{}
}
var _ Status_FieldPathArrayOfValues = (*Status_FieldTerminalPathArrayOfValues)(nil)
func (fpaov *Status_FieldTerminalPathArrayOfValues) GetRawValues() (values []interface{}) {
switch fpaov.selector {
case Status_FieldPathSelectorCode:
for _, v := range fpaov.values.([]int32) {
values = append(values, v)
}
case Status_FieldPathSelectorMessage:
for _, v := range fpaov.values.([]string) {
values = append(values, v)
}
case Status_FieldPathSelectorDetails:
for _, v := range fpaov.values.([][]*any.Any) {
values = append(values, v)
}
}
return
}
func (fpaov *Status_FieldTerminalPathArrayOfValues) AsCodeArrayOfValues() ([]int32, bool) {
res, ok := fpaov.values.([]int32)
return res, ok
}
func (fpaov *Status_FieldTerminalPathArrayOfValues) AsMessageArrayOfValues() ([]string, bool) {
res, ok := fpaov.values.([]string)
return res, ok
}
func (fpaov *Status_FieldTerminalPathArrayOfValues) AsDetailsArrayOfValues() ([][]*any.Any, bool) {
res, ok := fpaov.values.([][]*any.Any)
return res, ok
}