|
|
|
@ -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,7 +333,7 @@ func (s *Server) Start() (*Server, error) { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
}() |
|
|
|
|
return s, nil |
|
|
|
|
return lis.Addr(), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Serve accepts incoming connections on the listener lis, creating a new
|
|
|
|
|