更新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++ {
|
for i := 0; i < value.NumField(); i++ {
|
||||||
v := value.Field(i)
|
v := value.Field(i)
|
||||||
|
|
||||||
if v.IsValid() {
|
if v.IsValid() {
|
||||||
_namingClient, ok := v.Interface().(naming_client.INamingClient)
|
_namingClient, ok := v.Interface().(naming_client.INamingClient)
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -42,7 +41,6 @@ func AutoGrpcInit(obj any) {
|
||||||
|
|
||||||
{{range .ClientParams}}
|
{{range .ClientParams}}
|
||||||
|
|
||||||
|
|
||||||
func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
||||||
if namingClient == nil {
|
if namingClient == nil {
|
||||||
log.Println("nameClient must be init. call")
|
log.Println("nameClient must be init. call")
|
||||||
|
@ -54,27 +52,25 @@ func Auto{{.ClientName}}Client(ctx context.Context) {{.ClientName}}Client {
|
||||||
GroupName: groupName,
|
GroupName: groupName,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
if insService.Enable && insService.Healthy {
|
if insService.Enable && insService.Healthy {
|
||||||
|
|
||||||
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
return New{{.ClientName}}Client(conn)
|
return New{{.ClientName}}Client(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Println(fmt.Errorf("no healthy with times 3"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func Auto{{.ClientName}}ClientEx(ctx context.Context, opts ...grpc.DialOption) ({{.ClientName}}Client,error) {
|
func Auto{{.ClientName}}ClientEx(ctx context.Context, opts ...grpc.DialOption) ({{.ClientName}}Client,error) {
|
||||||
if namingClient == nil {
|
if namingClient == nil {
|
||||||
return nil, fmt.Errorf("nameClient must be init. call")
|
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,
|
GroupName: groupName,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
insService, err := namingClient.SelectOneHealthyInstance(sel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
log.Println(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if insService.Enable && insService.Healthy {
|
if insService.Enable && insService.Healthy {
|
||||||
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), opts...)
|
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", insService.Ip, insService.Port), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
log.Println(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
return New{{.ClientName}}Client(conn), nil
|
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}}
|
{{end}}
|
Loading…
Reference in New Issue
Block a user