...
1
18
19 package grpclb
20
21 import (
22 "encoding/json"
23
24 "google.golang.org/grpc"
25 "google.golang.org/grpc/balancer/roundrobin"
26 "google.golang.org/grpc/serviceconfig"
27 )
28
29 const (
30 roundRobinName = roundrobin.Name
31 pickFirstName = grpc.PickFirstBalancerName
32 )
33
34 type grpclbServiceConfig struct {
35 serviceconfig.LoadBalancingConfig
36 ChildPolicy *[]map[string]json.RawMessage
37 ServiceName string
38 }
39
40 func (b *lbBuilder) ParseConfig(lbConfig json.RawMessage) (serviceconfig.LoadBalancingConfig, error) {
41 ret := &grpclbServiceConfig{}
42 if err := json.Unmarshal(lbConfig, ret); err != nil {
43 return nil, err
44 }
45 return ret, nil
46 }
47
48 func childIsPickFirst(sc *grpclbServiceConfig) bool {
49 if sc == nil {
50 return false
51 }
52 childConfigs := sc.ChildPolicy
53 if childConfigs == nil {
54 return false
55 }
56 for _, childC := range *childConfigs {
57
58 if _, ok := childC[roundRobinName]; ok {
59 return false
60 }
61
62 if _, ok := childC[pickFirstName]; ok {
63 return true
64 }
65 }
66 return false
67 }
68
View as plain text