更新grpc
This commit is contained in:
parent
d8f0e584e0
commit
a5165828ba
|
@ -30,7 +30,6 @@ func AutoGrpcInit(obj any) {
|
|||
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
v := value.Field(i)
|
||||
|
||||
if v.IsValid() {
|
||||
_namingClient, ok := v.Interface().(naming_client.INamingClient)
|
||||
if ok {
|
||||
|
@ -42,7 +41,6 @@ func AutoGrpcInit(obj any) {
|
|||
|
||||
{{range .ClientParams}}
|
||||
|
||||
|
||||
func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
||||
if namingClient == nil {
|
||||
log.Println("nameClient must be init. call")
|
||||
|
@ -54,27 +52,25 @@ func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
|||
GroupName: groupName,
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := 0; i < 3; i++ {
|
||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
continue
|
||||
}
|
||||
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
|
||||
continue
|
||||
}
|
||||
return New{{.ClientName}}Client(conn)
|
||||
}
|
||||
}
|
||||
log.Println(fmt.Errorf("no healthy with times 3"))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
func Auto{{.ClientName}}ClientEx(ctx context.Context, opts ...grpc.DialOption) ({{.ClientName}}Client,error) {
|
||||
if namingClient == nil {
|
||||
return nil, fmt.Errorf("nameClient must be init. call")
|
||||
|
@ -85,21 +81,23 @@ func Auto{{.ClientName}}ClientEx(ctx context.Context, opts ...grpc.DialOption) (
|
|||
GroupName: groupName,
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := 0; i < 3; i++ {
|
||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
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
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
return New{{.ClientName}}Client(conn), nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no healthy with times 10")
|
||||
return nil, fmt.Errorf("no healthy with times 3")
|
||||
}
|
||||
|
||||
{{end}}
|
Loading…
Reference in New Issue
Block a user