Пример #1
0
func serveCmd(args []string) {
	fs := flag.NewFlagSet("serve", flag.ExitOnError)
	httpAddr := fs.String("http", ":1759", "HTTP service address")
	fs.Usage = func() {
		fmt.Fprintln(os.Stderr, `usage: maestro serve [options]

Starts the web server that serves the app and API.

The options are:
`)
		fs.PrintDefaults()
		os.Exit(1)
	}
	fs.Parse(args)

	if fs.NArg() != 0 {
		fs.Usage()
	}

	go baton.Run()
	m := http.NewServeMux()
	m.Handle("/baton/", http.StripPrefix("/baton", baton.Handler()))
	m.Handle("/", app.Handler())

	log.Print("Listening on ", *httpAddr)
	if err := http.ListenAndServe(*httpAddr, m); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
Пример #2
0
func serveCmd(args []string) {
	fs := flag.NewFlagSet("serve", flag.ExitOnError)
	httpAddr := fs.String("http", ":1759", "HTTP service address")
	fs.Usage = func() {
		fmt.Fprintln(os.Stderr, `usage: maestro serve [options]

Starts the web server that serves the app and API.

The options are:
`)
		fs.PrintDefaults()
		os.Exit(1)
	}
	fs.Parse(args)

	if fs.NArg() != 0 {
		fs.Usage()
	}

	hub := baton.NewHub()

	hub.InitModules(map[string]baton.Module{
		"Echo":  echo.Echo{},
		"Giphy": giphy.Giphy{"dc6zaTOxFJmzC"}, //testing key from Giphy
		"Neutrino": neutrino.Neutrino{"user-id",
			"api-key"},
		"Twilio": twilio.Twilio{"user-id",
			"api-key"},
	})
	go hub.Run()
	m := http.NewServeMux()
	m.Handle("/baton/", http.StripPrefix("/baton", hub.Handler()))
	m.Handle("/", app.Handler())

	log.Print("Listening on ", *httpAddr)
	if err := http.ListenAndServe(*httpAddr, m); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}