|
|
@ -156,8 +156,6 @@ func NewServer(opts ...ServerOption) *Server { |
|
|
|
} |
|
|
|
} |
|
|
|
srv.Server = grpc.NewServer(grpcOpts...) |
|
|
|
srv.Server = grpc.NewServer(grpcOpts...) |
|
|
|
srv.metadata = apimd.NewServer(srv.Server) |
|
|
|
srv.metadata = apimd.NewServer(srv.Server) |
|
|
|
// listen and endpoint
|
|
|
|
|
|
|
|
srv.err = srv.listenAndEndpoint() |
|
|
|
|
|
|
|
// internal register
|
|
|
|
// internal register
|
|
|
|
grpc_health_v1.RegisterHealthServer(srv.Server, srv.health) |
|
|
|
grpc_health_v1.RegisterHealthServer(srv.Server, srv.health) |
|
|
|
apimd.RegisterMetadataServer(srv.Server, srv.metadata) |
|
|
|
apimd.RegisterMetadataServer(srv.Server, srv.metadata) |
|
|
@ -169,7 +167,7 @@ func NewServer(opts ...ServerOption) *Server { |
|
|
|
// examples:
|
|
|
|
// examples:
|
|
|
|
// grpc://127.0.0.1:9000?isSecure=false
|
|
|
|
// grpc://127.0.0.1:9000?isSecure=false
|
|
|
|
func (s *Server) Endpoint() (*url.URL, error) { |
|
|
|
func (s *Server) Endpoint() (*url.URL, error) { |
|
|
|
if s.err != nil { |
|
|
|
if err := s.listenAndEndpoint(); err != nil { |
|
|
|
return nil, s.err |
|
|
|
return nil, s.err |
|
|
|
} |
|
|
|
} |
|
|
|
return s.endpoint, nil |
|
|
|
return s.endpoint, nil |
|
|
@ -177,7 +175,7 @@ func (s *Server) Endpoint() (*url.URL, error) { |
|
|
|
|
|
|
|
|
|
|
|
// Start start the gRPC server.
|
|
|
|
// Start start the gRPC server.
|
|
|
|
func (s *Server) Start(ctx context.Context) error { |
|
|
|
func (s *Server) Start(ctx context.Context) error { |
|
|
|
if s.err != nil { |
|
|
|
if err := s.listenAndEndpoint(); err != nil { |
|
|
|
return s.err |
|
|
|
return s.err |
|
|
|
} |
|
|
|
} |
|
|
|
s.baseCtx = ctx |
|
|
|
s.baseCtx = ctx |
|
|
@ -198,15 +196,17 @@ func (s *Server) listenAndEndpoint() error { |
|
|
|
if s.lis == nil { |
|
|
|
if s.lis == nil { |
|
|
|
lis, err := net.Listen(s.network, s.address) |
|
|
|
lis, err := net.Listen(s.network, s.address) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
s.err = err |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
addr, err := host.Extract(s.address, lis) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
_ = s.lis.Close() |
|
|
|
|
|
|
|
s.err = err |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
s.lis = lis |
|
|
|
s.lis = lis |
|
|
|
|
|
|
|
s.endpoint = endpoint.NewEndpoint(endpoint.Scheme("grpc", s.tlsConf != nil), addr) |
|
|
|
} |
|
|
|
} |
|
|
|
addr, err := host.Extract(s.address, s.lis) |
|
|
|
return s.err |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
_ = s.lis.Close() |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
s.endpoint = endpoint.NewEndpoint(endpoint.Scheme("grpc", s.tlsConf != nil), addr) |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|