master
icechen 2021-12-30 00:52:33 +08:00
parent a08010b83d
commit 4892847915
1 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package rpc package rpc
import ( import (
"fmt"
"google.golang.org/grpc" "google.golang.org/grpc"
"os" "os"
"strings" "strings"
@ -9,6 +10,10 @@ import (
// GetServiceConn 获取服务的连接 // GetServiceConn 获取服务的连接
func GetServiceConn(serviceName string) *grpc.ClientConn { func GetServiceConn(serviceName string) *grpc.ClientConn {
target := strings.ToUpper(os.Getenv("SERVICE_" + serviceName)) target := strings.ToUpper(os.Getenv("SERVICE_" + serviceName))
cli, _ := grpc.Dial(target, grpc.WithInsecure()) cli, err := grpc.Dial(target, grpc.WithInsecure())
if err != nil {
fmt.Println("target: " + target + " err: " + err.Error())
return nil
}
return cli return cli
} }