-
Notifications
You must be signed in to change notification settings - Fork 762
/
api.go
715 lines (604 loc) · 18.3 KB
/
api.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
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
package client
import (
"time"
"github.com/fagongzi/gateway/pkg/pb"
"github.com/fagongzi/gateway/pkg/pb/metapb"
"github.com/fagongzi/gateway/pkg/pb/rpcpb"
)
// APIBuilder api builder
type APIBuilder struct {
c *client
value metapb.API
}
// NewAPIBuilder return a api build
func (c *client) NewAPIBuilder() *APIBuilder {
return &APIBuilder{
c: c,
value: metapb.API{},
}
}
// Use use a cluster
func (ab *APIBuilder) Use(value metapb.API) *APIBuilder {
ab.value = value
return ab
}
// Name set a name
func (ab *APIBuilder) Name(name string) *APIBuilder {
ab.value.Name = name
return ab
}
// AuthPlugin set a auth filter plugin
func (ab *APIBuilder) AuthPlugin(name string) *APIBuilder {
ab.value.AuthFilter = name
return ab
}
// AddPerm add a perm
func (ab *APIBuilder) AddPerm(perm string) *APIBuilder {
ab.value.Perms = append(ab.value.Perms, perm)
return ab
}
// RemovePerm remove a perm
func (ab *APIBuilder) RemovePerm(perm string) *APIBuilder {
if len(ab.value.Perms) == 0 {
return ab
}
var perms []string
for _, p := range ab.value.Perms {
if p != perm {
perms = append(perms, p)
}
}
ab.value.Perms = perms
return ab
}
// WebSocketOptions set websocket options
func (ab *APIBuilder) WebSocketOptions(options *metapb.WebSocketOptions) *APIBuilder {
ab.value.WebSocketOptions = options
return ab
}
// MatchURLPattern set a match path
func (ab *APIBuilder) MatchURLPattern(urlPattern string) *APIBuilder {
ab.value.URLPattern = urlPattern
ab.value.Domain = ""
return ab
}
// MatchMethod set a match method
func (ab *APIBuilder) MatchMethod(method string) *APIBuilder {
ab.value.Method = method
ab.value.Domain = ""
return ab
}
// MatchDomain set a match domain
func (ab *APIBuilder) MatchDomain(domain string) *APIBuilder {
ab.value.Domain = domain
ab.value.Method = ""
ab.value.URLPattern = ""
return ab
}
// UP up this api
func (ab *APIBuilder) UP() *APIBuilder {
ab.value.Status = metapb.Up
return ab
}
// Down down this api
func (ab *APIBuilder) Down() *APIBuilder {
ab.value.Status = metapb.Down
return ab
}
// NoDefaultValue set no default value
func (ab *APIBuilder) NoDefaultValue() *APIBuilder {
ab.value.DefaultValue = nil
return ab
}
// DefaultValue set default value
func (ab *APIBuilder) DefaultValue(value []byte) *APIBuilder {
if ab.value.DefaultValue == nil {
ab.value.DefaultValue = &metapb.HTTPResult{}
}
ab.value.DefaultValue.Body = value
return ab
}
// UseDefaultValue use default value if force
func (ab *APIBuilder) UseDefaultValue(force bool) *APIBuilder {
ab.value.UseDefault = force
return ab
}
// AddDefaultValueHeader add default value header
func (ab *APIBuilder) AddDefaultValueHeader(name, value string) *APIBuilder {
if ab.value.DefaultValue == nil {
ab.value.DefaultValue = &metapb.HTTPResult{}
}
ab.value.DefaultValue.Headers = append(ab.value.DefaultValue.Headers, &metapb.PairValue{
Name: name,
Value: value,
})
return ab
}
// AddDefaultValueCookie add default value cookie
func (ab *APIBuilder) AddDefaultValueCookie(name, value string) *APIBuilder {
if ab.value.DefaultValue == nil {
ab.value.DefaultValue = &metapb.HTTPResult{}
}
ab.value.DefaultValue.Cookies = append(ab.value.DefaultValue.Cookies, &metapb.PairValue{
Name: name,
Value: value,
})
return ab
}
// NoWhitelist set no whiltelist
func (ab *APIBuilder) NoWhitelist() *APIBuilder {
if ab.value.IPAccessControl == nil {
return ab
}
ab.value.IPAccessControl.Whitelist = make([]string, 0, 0)
return ab
}
// NoBlacklist set no blacklist
func (ab *APIBuilder) NoBlacklist() *APIBuilder {
if ab.value.IPAccessControl == nil {
return ab
}
ab.value.IPAccessControl.Blacklist = make([]string, 0, 0)
return ab
}
// RemoveWhitelist remove ip white list
func (ab *APIBuilder) RemoveWhitelist(ips ...string) *APIBuilder {
if ab.value.IPAccessControl == nil || len(ab.value.IPAccessControl.Whitelist) == 0 {
return ab
}
var value []string
for _, old := range ab.value.IPAccessControl.Whitelist {
for _, ip := range ips {
if old != ip {
value = append(value, old)
}
}
}
ab.value.IPAccessControl.Whitelist = value
return ab
}
// RemoveBlacklist remove ip white list
func (ab *APIBuilder) RemoveBlacklist(ips ...string) *APIBuilder {
if ab.value.IPAccessControl == nil || len(ab.value.IPAccessControl.Blacklist) == 0 {
return ab
}
var value []string
for _, old := range ab.value.IPAccessControl.Blacklist {
for _, ip := range ips {
if old != ip {
value = append(value, old)
}
}
}
ab.value.IPAccessControl.Blacklist = value
return ab
}
// AddWhitelist add ip white list
func (ab *APIBuilder) AddWhitelist(ips ...string) *APIBuilder {
if ab.value.IPAccessControl == nil {
ab.value.IPAccessControl = &metapb.IPAccessControl{}
}
ab.value.IPAccessControl.Whitelist = append(ab.value.IPAccessControl.Whitelist, ips...)
return ab
}
// AddBlacklist add ip black list
func (ab *APIBuilder) AddBlacklist(ips ...string) *APIBuilder {
if ab.value.IPAccessControl == nil {
ab.value.IPAccessControl = &metapb.IPAccessControl{}
}
ab.value.IPAccessControl.Blacklist = append(ab.value.IPAccessControl.Blacklist, ips...)
return ab
}
// AppendDispatchNode append a dispatch node even if the cluster added
func (ab *APIBuilder) AppendDispatchNode(cluster uint64) *APIBuilder {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
})
return ab
}
// AddDispatchNode add a dispatch node if the cluster not added
func (ab *APIBuilder) AddDispatchNode(cluster uint64) *APIBuilder {
for _, n := range ab.value.Nodes {
if n.ClusterID == cluster {
return ab
}
}
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
})
return ab
}
// DispatchNodeTimeouts add timeouts options
func (ab *APIBuilder) DispatchNodeTimeouts(cluster uint64, readTimeout, writeTimeout int64) *APIBuilder {
return ab.DispatchNodeTimeoutsWithIndex(cluster, 0, readTimeout, writeTimeout)
}
// DispatchNodeTimeoutsWithIndex add timeouts options
func (ab *APIBuilder) DispatchNodeTimeoutsWithIndex(cluster uint64, idx int, readTimeout, writeTimeout int64) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
})
} else {
node.ReadTimeout = readTimeout
node.WriteTimeout = writeTimeout
}
return ab
}
// DispatchNodeRetryStrategy add a retryStrategy
func (ab *APIBuilder) DispatchNodeRetryStrategy(cluster uint64, strategy *metapb.RetryStrategy) *APIBuilder {
return ab.DispatchNodeRetryStrategyWithIndex(cluster, 0, strategy)
}
// DispatchNodeRetryStrategyWithIndex add a retryStrategy
func (ab *APIBuilder) DispatchNodeRetryStrategyWithIndex(cluster uint64, idx int, strategy *metapb.RetryStrategy) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
RetryStrategy: strategy,
})
} else {
node.RetryStrategy = strategy
}
return ab
}
// DispatchNodeBatchIndex add a dispatch node batch index
func (ab *APIBuilder) DispatchNodeBatchIndex(cluster uint64, batchIndex int) *APIBuilder {
return ab.DispatchNodeBatchIndexWithIndex(cluster, 0, batchIndex)
}
// DispatchNodeBatchIndexWithIndex add a dispatch node batch index
func (ab *APIBuilder) DispatchNodeBatchIndexWithIndex(cluster uint64, idx int, batchIndex int) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
BatchIndex: int32(batchIndex),
})
} else {
node.BatchIndex = int32(batchIndex)
}
return ab
}
// AddDispatchNodeDefaultValue add default value for dispatch
func (ab *APIBuilder) AddDispatchNodeDefaultValue(cluster uint64, value []byte) *APIBuilder {
return ab.AddDispatchNodeDefaultValueWithIndex(cluster, 0, value)
}
// AddDispatchNodeDefaultValueWithIndex add default value for dispatch
func (ab *APIBuilder) AddDispatchNodeDefaultValueWithIndex(cluster uint64, idx int, value []byte) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
DefaultValue: &metapb.HTTPResult{
Body: value,
},
})
} else {
if node.DefaultValue == nil {
node.DefaultValue = &metapb.HTTPResult{
Body: value,
}
} else {
node.DefaultValue.Body = value
}
}
return ab
}
// UseDispatchNodeDefaultValue use default value if force
func (ab *APIBuilder) UseDispatchNodeDefaultValue(cluster uint64, force bool) *APIBuilder {
return ab.UseDispatchNodeDefaultValueWithIndex(cluster, 0, force)
}
// UseDispatchNodeDefaultValueWithIndex use default value if force
func (ab *APIBuilder) UseDispatchNodeDefaultValueWithIndex(cluster uint64, idx int, force bool) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
UseDefault: force,
})
} else {
node.UseDefault = force
}
return ab
}
// AddDispatchNodeDefaultValueHeader add default value header
func (ab *APIBuilder) AddDispatchNodeDefaultValueHeader(cluster uint64, name, value string) *APIBuilder {
return ab.AddDispatchNodeDefaultValueHeaderWithIndex(cluster, 0, name, value)
}
// AddDispatchNodeDefaultValueHeaderWithIndex add default value header
func (ab *APIBuilder) AddDispatchNodeDefaultValueHeaderWithIndex(cluster uint64, idx int, name, value string) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
DefaultValue: &metapb.HTTPResult{
Headers: []*metapb.PairValue{
&metapb.PairValue{
Name: name,
Value: value,
},
},
},
})
} else {
if node.DefaultValue == nil {
node.DefaultValue = &metapb.HTTPResult{
Headers: []*metapb.PairValue{
&metapb.PairValue{
Name: name,
Value: value,
},
},
}
} else {
node.DefaultValue.Headers = append(node.DefaultValue.Headers, &metapb.PairValue{
Name: name,
Value: value,
})
}
}
return ab
}
// AddDispatchNodeDefaultValueCookie add default value cookie
func (ab *APIBuilder) AddDispatchNodeDefaultValueCookie(cluster uint64, name, value string) *APIBuilder {
return ab.AddDispatchNodeDefaultValueCookieWithIndex(cluster, 0, name, value)
}
// AddDispatchNodeDefaultValueCookieWithIndex add default value cookie
func (ab *APIBuilder) AddDispatchNodeDefaultValueCookieWithIndex(cluster uint64, idx int, name, value string) *APIBuilder {
node := ab.getNode(cluster, idx)
if nil == node {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
DefaultValue: &metapb.HTTPResult{
Cookies: []*metapb.PairValue{
&metapb.PairValue{
Name: name,
Value: value,
},
},
},
})
} else {
if node.DefaultValue == nil {
node.DefaultValue = &metapb.HTTPResult{
Cookies: []*metapb.PairValue{
&metapb.PairValue{
Name: name,
Value: value,
},
},
}
} else {
node.DefaultValue.Cookies = append(node.DefaultValue.Cookies, &metapb.PairValue{
Name: name,
Value: value,
})
}
}
return ab
}
// RemoveDispatchNodeURLRewrite remove dispatch node
func (ab *APIBuilder) RemoveDispatchNodeURLRewrite(cluster uint64) *APIBuilder {
for _, n := range ab.value.Nodes {
if n.ClusterID == cluster {
n.URLRewrite = ""
}
}
return ab
}
// DispatchNodeUseCachingWithIndex set dispatch node caching
func (ab *APIBuilder) DispatchNodeUseCachingWithIndex(cluster uint64, index int, deadline time.Duration) *APIBuilder {
node := ab.getNode(cluster, index)
if node == nil {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
Cache: &metapb.Cache{
Deadline: uint64(deadline.Seconds()),
},
})
} else {
node.Cache = &metapb.Cache{
Deadline: uint64(deadline.Seconds()),
}
}
return ab
}
// DispatchNodeUseCaching set dispatch node caching
func (ab *APIBuilder) DispatchNodeUseCaching(cluster uint64, deadline time.Duration) *APIBuilder {
return ab.DispatchNodeUseCachingWithIndex(cluster, 0, deadline)
}
// AddDispatchNodeCachingKeyWithIndex add key for caching
func (ab *APIBuilder) AddDispatchNodeCachingKeyWithIndex(cluster uint64, index int, keys ...metapb.Parameter) *APIBuilder {
node := ab.getNode(cluster, index)
if node != nil {
node.Cache.Keys = append(node.Cache.Keys, keys...)
}
return ab
}
// AddDispatchNodeCachingKey add key for caching
func (ab *APIBuilder) AddDispatchNodeCachingKey(cluster uint64, keys ...metapb.Parameter) *APIBuilder {
return ab.AddDispatchNodeCachingKeyWithIndex(cluster, 0, keys...)
}
// AddDispatchNodeCachingConditionWithIndex add condition for caching
func (ab *APIBuilder) AddDispatchNodeCachingConditionWithIndex(cluster uint64, index int, param metapb.Parameter, op metapb.CMP, expect string) *APIBuilder {
node := ab.getNode(cluster, index)
if node != nil {
node.Cache.Conditions = append(node.Cache.Conditions, metapb.Condition{
Parameter: param,
Cmp: op,
Expect: expect,
})
}
return ab
}
// AddDispatchNodeCachingCondition add condition for caching
func (ab *APIBuilder) AddDispatchNodeCachingCondition(cluster uint64, param metapb.Parameter, op metapb.CMP, expect string) *APIBuilder {
return ab.AddDispatchNodeCachingConditionWithIndex(cluster, 0, param, op, expect)
}
// DispatchNodeURLRewriteWithIndex set dispatch node url rewrite
func (ab *APIBuilder) DispatchNodeURLRewriteWithIndex(cluster uint64, index int, urlRewrite string) *APIBuilder {
node := ab.getNode(cluster, index)
if node == nil {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
URLRewrite: urlRewrite,
})
} else {
node.URLRewrite = urlRewrite
}
return ab
}
// DispatchNodeURLRewrite set dispatch node url rewrite
func (ab *APIBuilder) DispatchNodeURLRewrite(cluster uint64, urlRewrite string) *APIBuilder {
return ab.DispatchNodeURLRewriteWithIndex(cluster, 0, urlRewrite)
}
// DispatchNodeValueAttrNameWithIndex set dispatch node attr name of value
func (ab *APIBuilder) DispatchNodeValueAttrNameWithIndex(cluster uint64, index int, attrName string) *APIBuilder {
node := ab.getNode(cluster, index)
if node == nil {
ab.value.Nodes = append(ab.value.Nodes, &metapb.DispatchNode{
ClusterID: cluster,
AttrName: attrName,
})
} else {
node.AttrName = attrName
}
return ab
}
// DispatchNodeValueAttrName set dispatch node attr name of value
func (ab *APIBuilder) DispatchNodeValueAttrName(cluster uint64, attrName string) *APIBuilder {
return ab.DispatchNodeValueAttrNameWithIndex(cluster, 0, attrName)
}
// AddDispatchNodeValidationWithIndex add dispatch node validation
func (ab *APIBuilder) AddDispatchNodeValidationWithIndex(cluster uint64, index int, param metapb.Parameter, rule string, required bool) *APIBuilder {
node := ab.getNode(cluster, index)
if node == nil {
node = &metapb.DispatchNode{
ClusterID: cluster,
}
ab.value.Nodes = append(ab.value.Nodes, node)
}
var validation *metapb.Validation
for _, v := range node.Validations {
if v.Parameter.Name == param.Name && v.Parameter.Source == param.Source {
validation = v
break
}
}
if validation == nil {
validation = &metapb.Validation{
Parameter: param,
Required: required,
}
node.Validations = append(node.Validations, validation)
}
validation.Rules = append(validation.Rules, metapb.ValidationRule{
RuleType: metapb.RuleRegexp,
Expression: rule,
})
return ab
}
// AddDispatchNodeValidation add dispatch node validation
func (ab *APIBuilder) AddDispatchNodeValidation(cluster uint64, param metapb.Parameter, rule string, required bool) *APIBuilder {
return ab.AddDispatchNodeValidationWithIndex(cluster, 0, param, rule, required)
}
// NoRenderTemplate clear render template
func (ab *APIBuilder) NoRenderTemplate() *APIBuilder {
ab.value.RenderTemplate = nil
return ab
}
// AddFlatRenderObject add the render object to the top level object
func (ab *APIBuilder) AddFlatRenderObject(namesAndExtractExps ...string) *APIBuilder {
return ab.addRenderObject("", true, namesAndExtractExps...)
}
// AddRenderObject add the render object to the top level object
func (ab *APIBuilder) AddRenderObject(nameInTemplate string, namesAndExtractExps ...string) *APIBuilder {
return ab.addRenderObject(nameInTemplate, false, namesAndExtractExps...)
}
func (ab *APIBuilder) addRenderObject(nameInTemplate string, flatAttrs bool, namesAndExtractExps ...string) *APIBuilder {
if len(namesAndExtractExps) == 0 || len(namesAndExtractExps)%2 != 0 {
return ab
}
if ab.value.RenderTemplate == nil {
ab.value.RenderTemplate = &metapb.RenderTemplate{}
}
var obj *metapb.RenderObject
for _, o := range ab.value.RenderTemplate.Objects {
if o.Name == nameInTemplate {
obj = o
}
}
if obj == nil {
obj = &metapb.RenderObject{
Name: nameInTemplate,
FlatAttrs: flatAttrs,
}
ab.value.RenderTemplate.Objects = append(ab.value.RenderTemplate.Objects, obj)
}
l := len(namesAndExtractExps) / 2
for i := 0; i < l; i++ {
obj.Attrs = append(obj.Attrs, &metapb.RenderAttr{
Name: namesAndExtractExps[2*i],
ExtractExp: namesAndExtractExps[2*i+1],
})
}
return ab
}
// AddTag add tag for api
func (ab *APIBuilder) AddTag(key, value string) *APIBuilder {
ab.value.Tags = append(ab.value.Tags, &metapb.PairValue{
Name: key,
Value: value,
})
return ab
}
// RemoveTag remove tag for api
func (ab *APIBuilder) RemoveTag(key string) *APIBuilder {
var newTags []*metapb.PairValue
for _, tag := range ab.value.Tags {
if tag.Name != key {
newTags = append(newTags, tag)
}
}
ab.value.Tags = newTags
return ab
}
// Position reset the position for api
func (ab *APIBuilder) Position(value uint32) *APIBuilder {
ab.value.Position = value
return ab
}
// Commit commit
func (ab *APIBuilder) Commit() (uint64, error) {
err := pb.ValidateAPI(&ab.value)
if err != nil {
return 0, err
}
return ab.c.putAPI(ab.value)
}
// Build build
func (ab *APIBuilder) Build() (*rpcpb.PutAPIReq, error) {
err := pb.ValidateAPI(&ab.value)
if err != nil {
return nil, err
}
return &rpcpb.PutAPIReq{
API: ab.value,
}, nil
}
func (ab *APIBuilder) getNode(cluster uint64, index int) *metapb.DispatchNode {
var node *metapb.DispatchNode
idx := 0
for _, n := range ab.value.Nodes {
if n.ClusterID == cluster && idx == index {
node = n
break
}
if n.ClusterID == cluster {
idx++
}
}
return node
}