server.go
func (s *Server) ListenAndServe() error {
	mux := http.NewServeMux()
	mux.Handle("/", websocket.Server{
		Config:  s.wsConfig,
		Handler: s.wsConnHandler,
		Handshake: func(config *websocket.Config, req *http.Request) error {
			s.wg.Add(1)                                  // todo: this needs to happen inside the gorotune executing the Start method and not the request goroutine or we'll miss some edge connections
			config.Origin, _ = url.Parse(req.RemoteAddr) // we're interested in remote address and not origin header text
			return nil
		},
	})

	l, err := net.Listen("tcp", s.addr)
	if err != nil {
		return fmt.Errorf("failed to create TLS listener on network address %v with error: %v", s.addr, err)
	}
	s.listener = l

	log.Printf("server: started %v", s.addr)
	s.running.Store(true)
	err = http.Serve(l, mux)
	if !s.running.Load().(bool) {
		return nil
	}
	return err
}
func (s *Server) ListenAndServe() error {
	mux := http.NewServeMux()
	mux.Handle("/", websocket.Server{
		Config:  s.wsConfig,
		Handler: s.wsConnHandler,
		Handshake: func(config *websocket.Config, req *http.Request) error {
			s.wg.Add(1)                                  // todo: this needs to happen inside the gorotune executing the Start method and not the request goroutine or we'll miss some edge connections
			config.Origin, _ = url.Parse(req.RemoteAddr) // we're interested in remote address and not origin header text
			return nil
		},
	})

	l, err := net.Listen("tcp", s.addr)
	if err != nil {
		return fmt.Errorf("failed to create TLS listener on network address %v with error: %v", s.addr, err)
	}
	s.listener = l

	log.Printf("server: started %v", s.addr)
	s.running.Store(true)
	err = http.Serve(l, mux)
	if !s.running.Load().(bool) {
		return nil
	}
	return err
}
// ListenAndServe starts the Neptulon server. This function blocks until server is closed.