Beispiel #1
0
// Listen creates the listeners for the server
func (s *Server) Listen() error {
	if s.hasListeners { // already done this
		return nil
	}
	domSockListener, err := net.Listen("unix", string(s.SocketPath))
	if err != nil {
		return err
	}
	s.domainSocketL = domSockListener
	listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.Host, s.Port))
	if err != nil {
		return err
	}

	h, p, err := swag.SplitHostPort(listener.Addr().String())
	if err != nil {
		return err
	}
	s.Host = h
	s.Port = p
	s.httpServerL = listener

	if s.TLSHost == "" {
		s.TLSHost = s.Host
	}
	tlsListener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.TLSHost, s.TLSPort))
	if err != nil {
		return err
	}

	sh, sp, err := swag.SplitHostPort(tlsListener.Addr().String())
	if err != nil {
		return err
	}
	s.TLSHost = sh
	s.TLSPort = sp
	s.httpsServerL = tlsListener
	s.hasListeners = true
	return nil
}
Beispiel #2
0
// Listen creates the listeners for the server
func (s *Server) Listen() error {
	if s.hasListeners { // already done this
		return nil
	}

	listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.Host, s.Port))
	if err != nil {
		return err
	}

	h, p, err := swag.SplitHostPort(listener.Addr().String())
	if err != nil {
		return err
	}
	s.Host = h
	s.Port = p
	s.httpServerL = listener

	s.hasListeners = true
	return nil
}