再次
This commit is contained in:
parent
ce53f9caa3
commit
e9a16ee7a2
|
@ -54,11 +54,13 @@ func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
|||
GroupName: groupName,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -67,6 +69,9 @@ func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
|||
}
|
||||
return New{{.ClientName}}Client(conn)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -80,16 +85,21 @@ func Auto{{.ClientName}}ClientEx(ctx context.Context, opts ...grpc.DialOption) (
|
|||
GroupName: groupName,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no healthy with times 10")
|
||||
}
|
||||
|
||||
{{end}}
|
Loading…
Reference in New Issue
Block a user