From bc876f20d66342e9dec4c7af066c2594170dec0c Mon Sep 17 00:00:00 2001 From: "suguo.yao" Date: Thu, 16 Sep 2021 13:55:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3grpc=20start=E6=97=B6?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E5=AF=BC=E8=87=B4=E7=AB=AF=E5=8F=A3=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=BA0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grpc/grpc.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/grpc/grpc.go b/grpc/grpc.go index c23e18a..b8e6e1e 100644 --- a/grpc/grpc.go +++ b/grpc/grpc.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net" + "sync" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -49,8 +50,9 @@ func Port() int { func Start() { //注册反射 用于grpcurl调试 reflection.Register(rpc) - - // grpc服务启动,本局IP支持 + wg := sync.WaitGroup{} + wg.Add(1) + // grpc服务启动 go func() { addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", conf.Address, conf.Port)) if err != nil { @@ -67,5 +69,7 @@ func Start() { if err != nil { log.Fatal("fail to open microservice: ", err) } + wg.Done() }() + wg.Wait() }