示例#1
0
func runServerWithGui(chain *nigella.Nigella) {
	var wg sync.WaitGroup

	listener, err := net.Listen("tcp", `127.0.0.1:0`)
	if err != nil {
		log.Fatalf("ERROR: %s", err.Error())
		return
	}
	port := listener.Addr().(*net.TCPAddr).Port
	portAsString := strconv.Itoa(port)

	log.Infof("Server Listing on http://localhost:%s ", portAsString)

	ServerFunc := func() {
		defer wg.Done()
		log.Info("Running Server")
		manners.Serve(listener, chain)
	}

	//===== start the GUI ===========
	GuiFunc := func() {
		defer wg.Done()

		time.Sleep(1 * time.Second)

		var exeRoot string
		var err error

		exeRoot, err = osext.ExecutableFolder()
		if err != nil {
			log.Fatalf("ERROR: %s", err.Error())
		} else {
			log.Info("EXE Root: " + exeRoot)
		}

		ClientFilePath := filepath.Join(exeRoot, `client`, `Malkovich Client.exe`)

		ClientCmd := exec.Command(ClientFilePath, portAsString)
		err = ClientCmd.Run()
		if err != nil {
			log.Fatal(err)
		}

		manners.Close()
	}

	wg.Add(1)
	wg.Add(1)
	go ServerFunc()
	go GuiFunc()
	wg.Wait()

	log.Info("Everything has finished.")
}
示例#2
0
文件: server.go 项目: vozhyk-/gohan
//Start starts GohanAPIServer
func (server *Server) Start() (err error) {
	listeners, err := listener.ListenAll()
	var l net.Listener
	if err != nil || len(listeners) == 0 {
		l, err = net.Listen("tcp", server.address)
		if err != nil {
			return err
		}
	} else {
		l = listeners[0]
	}
	if server.tls != nil {
		config := &tls.Config{}
		config.Certificates = make([]tls.Certificate, 1)
		config.Certificates[0], err = tls.LoadX509KeyPair(server.tls.CertFile, server.tls.KeyFile)
		if err != nil {
			return err
		}
		l = tls.NewListener(l, config)
	}
	return manners.Serve(l, server.martini)
}
示例#3
0
文件: main.go 项目: mono0x/my-scraper
func run() error {
	signalChan := make(chan os.Signal)
	signal.Notify(signalChan, syscall.SIGTERM)
	go func() {
		for {
			s := <-signalChan
			if s == syscall.SIGTERM {
				manners.Close()
			}
		}
	}()

	listeners, err := listener.ListenAll()
	if err != nil {
		return err
	}

	var l net.Listener
	if len(listeners) > 0 {
		l = listeners[0]
	} else {
		l, err = net.Listen("tcp", ":13000")
		if err != nil {
			return err
		}
	}

	mux := http.NewServeMux()

	entries := []struct {
		Path   string
		Source scraper.Source
	}{
		{"/character-show", scraper.NewCharacterShowSource()},
		{"/fukoku-life", scraper.NewFukokuLifeEventSource()},
		{"/harmonyland-info", scraper.NewHarmonylandInfoSource()},
		{"/kittychan-info", scraper.NewKittychanInfoSource()},
		{"/memoirs-of-shibasaki-saki", scraper.NewMemoirsOfShibasakiSakiSource()},
		{"/prtimes-sanrio", scraper.NewPRTimesSource()},
		{"/puroland-info", scraper.NewPurolandInfoSource()},
		{"/sanrio-news-release", scraper.NewSanrioNewsReleaseSource()},
		{"/seibuen-event", scraper.NewSeibuenEventSource()},
		{"/value-press-sanrio", scraper.NewValuePressSource()},
	}
	for _, entry := range entries {
		mux.HandleFunc(entry.Path, sourceRenderer(entry.Source))
	}

	mux.HandleFunc("/facebook", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		id := query.Get("id")
		if id == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewFacebookSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	mux.HandleFunc("/google-calendar", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		id := query.Get("id")
		if id == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewGoogleCalendarSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	mux.HandleFunc("/instagram", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		id := query.Get("id")
		if id == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewInstagramSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	mux.HandleFunc("/twitter", func(w http.ResponseWriter, r *http.Request) {
		query := r.URL.Query()
		idStr := query.Get("id")
		if idStr == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		id, err := strconv.ParseInt(idStr, 10, 64)
		if err != nil {
			w.WriteHeader(http.StatusNotFound)
			return
		}
		source := scraper.NewTwitterSource(id)
		feed, err := source.Scrape()
		if err != nil {
			log.Println(err)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}
		renderFeed(w, feed)
	})

	manners.Serve(l, mux)
	return nil
}