Esempio n. 1
0
func main() {

	sigint.ListenForSIGINT(func() {
		server.Shutdown()
	})

	app := getApp()
	app.Run(os.Args)

}
Esempio n. 2
0
func main() {
	var err error

	flag.Parse()
	runtime.GOMAXPROCS(runtime.NumCPU())

	/*
	 * Handle SIGINT (CTRL+C)
	 */
	sigint.ListenForSIGINT(func() {
		log.Println("Shutting down...")
		os.Exit(0)
	})

	/*
	 * Setup database
	 */
	connectionInfo, err := environment.GetSqlConnectionInformation()
	if err != nil {
		log.Fatal(err)
	}

	err = database.ConnectMySQL(connectionInfo)
	if err != nil {
		log.Fatal(err)
	}

	/*
	 * Setup routing and middleware
	 */
	router := bootstrapper.SetupWebRouter()
	middleware := alice.New(auth, logger).Then(router)

	/*
	 * Start web server
	 */
	log.Printf("Texo Services setup on %s:%d\n\n", *serverAddress, *serverPort)
	http.ListenAndServe(fmt.Sprintf("%s:%d", *serverAddress, *serverPort), middleware)
}
Esempio n. 3
0
func main() {
	var err error
	runtime.GOMAXPROCS(runtime.NumCPU())

	log.Printf("MailSlurper: INFO - Starting MailSlurper Server v%s\n", global.SERVER_VERSION)
	/*
	 * Prepare SIGINT handler (CTRL+C)
	 */
	sigint.ListenForSIGINT(func() {
		log.Println("MailSlurper: INFO - Shutting down via SIGINT.")
		os.Exit(0)
	})

	/*
	 * Load configuration
	 */
	config, err := configuration.LoadConfigurationFromFile(configuration.CONFIGURATION_FILE_NAME)
	if err != nil {
		log.Println("MailSlurper: ERROR - There was an error reading your configuration file:", err)
		os.Exit(0)
	}

	/*
	 * Setup global database connection handle
	 */
	databaseConnection := config.GetDatabaseConfiguration()

	if err = storage.ConnectToStorage(databaseConnection); err != nil {
		log.Println("MailSlurper: ERROR - There was an error connecting to your data storage:", err)
		os.Exit(0)
	}

	defer storage.DisconnectFromStorage()

	/*
	 * Setup the server pool
	 */
	pool := server.NewServerPool(config.MaxWorkers)

	/*
	 * Setup the SMTP listener
	 */
	smtpServer, err := server.SetupSmtpServerListener(config.GetFullSmtpBindingAddress())
	if err != nil {
		log.Println("MailSlurper: ERROR - There was a problem starting the SMTP listener:", err)
		os.Exit(0)
	}

	defer server.CloseSmtpServerListener(smtpServer)

	/*
	 * Setup receivers (subscribers) to handle new mail items.
	 */
	receivers := []receiver.IMailItemReceiver{
		receiver.DatabaseReceiver{},
	}

	/*
	 * Start the SMTP dispatcher
	 */
	go server.Dispatcher(pool, smtpServer, receivers)

	/*
	 * Pre-load layout information
	 */
	layout, err := GoHttpService.NewLayout("./www/", []string{
		"assets/mailslurper/layouts/mainLayout",
	})

	if err != nil {
		log.Printf("MailSlurper: ERROR - Error setting up layout: %s\n", err.Error())
		os.Exit(1)
	}

	/*
	 * Application context gets passed around all over the place
	 */
	appContext := &middleware.AppContext{
		Config: config,
		Layout: layout,
	}

	httpListener := listener.NewHTTPListenerService(config.WWWAddress, config.WWWPort, appContext)

	setupMiddleware(httpListener, appContext)
	setupRoutes(httpListener, appContext)

	/*
	 * Setup the app HTTP listener
	 */
	go func() {
		if err := httpListener.StartHTTPListener(); err != nil {
			log.Printf("MailSlurper: ERROR - Error starting HTTP listener: %s\n", err.Error())
			os.Exit(1)
		}
	}()

	/*
	 * Start the services server
	 */
	err = serviceListener.StartHttpListener(serviceListener.NewHttpListener(config.ServiceAddress, config.ServicePort))

	if err != nil {
		log.Printf("MailSlurper: ERROR - Error starting MailSlurper services server: %s\n", err.Error())
	}
}