This commit is contained in:
2026-09-22 22:15:25 +08:00
parent 4c710bf943
commit 9d5411b62a

View File

@@ -20,7 +20,12 @@ type Server struct {
grpcConns map[string]*grpc.ClientConn // 连接池 grpcConns map[string]*grpc.ClientConn // 连接池
} }
func New(addr string) *Server { func New(grpcServ *grpc.Server) *Server {
standalone := grpcServ == nil
if standalone {
grpcServ = grpc.NewServer()
}
srv := &Server{ srv := &Server{
Ctx: context.Background(), Ctx: context.Background(),
Grpc: grpc.NewServer(), Grpc: grpc.NewServer(),
@@ -32,6 +37,10 @@ func New(addr string) *Server {
reflection.Register(srv.Grpc) reflection.Register(srv.Grpc)
if standalone {
reflection.Register(srv.Grpc)
}
return srv return srv
} }