robotLJW commented on a change in pull request #1205:
URL: 
https://github.com/apache/servicecomb-service-center/pull/1205#discussion_r779973126



##########
File path: client/set.go
##########
@@ -20,11 +24,33 @@ type Set struct {
 
 // NewSetForConfig dial grpc connection and create all grpc clients
 func NewSetForConfig(c SetConfig) (*Set, error) {
-       conn, err := grpc.Dial(c.Addr, grpc.WithInsecure())
+       if len(c.Addr) <= 0 {
+               return nil, errors.New("addr is empty")
+       }
+
+       var conn *grpc.ClientConn
+       var err error
+
+       if len(c.Addr) <= 1 {
+               conn, err = grpc.Dial(c.Addr[0], grpc.WithInsecure())
+       } else {
+               addr := make([]resolver.Address, 0, len(c.Addr))
+               for _, a := range c.Addr {
+                       addr = append(addr, resolver.Address{Addr: a})
+               }
+               r := manual.NewBuilderWithScheme(c.Scheme)
+               r.InitialState(resolver.State{Addresses: addr})
+               conn, err = grpc.Dial(r.Scheme()+":///", grpc.WithInsecure(), 
grpc.WithResolvers(r))
+       }
+
        if err != nil {
                log.Error(fmt.Sprintf("can not connect: %s", err), nil)
                return nil, err
        }
+       if conn == nil {
+               return nil, errors.New("conn is nil")

Review comment:
       这个也是一样,主要是为了方便共用




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to