再次
This commit is contained in:
parent
ce53f9caa3
commit
e9a16ee7a2
|
@ -54,18 +54,23 @@ func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
|||
GroupName: groupName,
|
||||
}
|
||||
|
||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
}
|
||||
if insService.Enable && insService.Healthy {
|
||||
|
||||
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
}
|
||||
return New{{.ClientName}}Client(conn)
|
||||
}
|
||||
}
|
||||
return New{{.ClientName}}Client(conn)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,16 +85,21 @@ func Auto{{.ClientName}}ClientEx(ctx context.Context, opts ...grpc.DialOption) (
|
|||
GroupName: groupName,
|
||||
}
|
||||
|
||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for i := 0; i < 10; i++ {
|
||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if insService.Enable && insService.Healthy {
|
||||
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New{{.ClientName}}Client(conn), nil
|
||||
}
|
||||
}
|
||||
|
||||
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New{{.ClientName}}Client(conn), nil
|
||||
return nil, fmt.Errorf("no healthy with times 10")
|
||||
}
|
||||
|
||||
{{end}}
|
Loading…
Reference in New Issue
Block a user