mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
refine warden server start
This commit is contained in:
parent
d6a78697e7
commit
232419458d
@ -302,6 +302,26 @@ func (s *Server) RunUnix(file string) error {
|
||||
// will panic if any error happend
|
||||
// return server itself
|
||||
func (s *Server) Start() (*Server, error) {
|
||||
_, err := s.startWithAddr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// StartWithAddr create a new goroutine run server with configured listen addr
|
||||
// will panic if any error happend
|
||||
// return server itself and the actually listened address (if configured listen
|
||||
// port is zero, the os will allocate an unused port)
|
||||
func (s *Server) StartWithAddr() (*Server, net.Addr, error) {
|
||||
addr, err := s.startWithAddr()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return s, addr, nil
|
||||
}
|
||||
|
||||
func (s *Server) startWithAddr() (net.Addr, error) {
|
||||
lis, err := net.Listen(s.conf.Network, s.conf.Addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -313,26 +333,7 @@ func (s *Server) Start() (*Server, error) {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// StartWithAddr create a new goroutine run server with configured listen addr
|
||||
// will panic if any error happend
|
||||
// return server itself and the actually listened address (if configured listen
|
||||
// port is zero, the os will allocate an unused port)
|
||||
func (s *Server) StartWithAddr() (*Server, net.Addr, error) {
|
||||
lis, err := net.Listen(s.conf.Network, s.conf.Addr)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
log.Info("warden: start grpc listen addr: %v", lis.Addr())
|
||||
reflection.Register(s.server)
|
||||
go func() {
|
||||
if err := s.Serve(lis); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
return s, lis.Addr(), nil
|
||||
return lis.Addr(), nil
|
||||
}
|
||||
|
||||
// Serve accepts incoming connections on the listener lis, creating a new
|
||||
|
Loading…
x
Reference in New Issue
Block a user