refactor: add unified all service gateway
This commit is contained in:
@@ -17,17 +17,24 @@ type Server struct {
|
||||
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{
|
||||
Ctx: context.Background(),
|
||||
Grpc: grpc.NewServer(),
|
||||
Grpc: grpcServ,
|
||||
grpcConns: make(map[string]*grpc.ClientConn),
|
||||
}
|
||||
|
||||
// register service to grpc.Server
|
||||
pb.RegisterLibraryServer(srv.Grpc, NewLibraryServer())
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
if standalone {
|
||||
reflection.Register(srv.Grpc)
|
||||
}
|
||||
|
||||
return srv
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user