예제 #1
0
파일: run.go 프로젝트: escribano/charon
func runCommandAction(context *cli.Context) {
	service.InitConfig(context.GlobalString("environment"))
	service.InitLogger(service.Config.Logger)
	service.InitDB(service.Config.DB)
	service.InitMnemosyne(service.Config.Mnemosyne)
	service.InitRepositoryManager(service.DBPool)
	service.InitPasswordHasher(service.Config.PasswordHasher)
	service.InitTranslation(service.Config.Translation)
	service.InitRouting(service.Config.Routing)
	service.InitTemplateManager(service.Config.Templates)
	service.InitMailers(service.Config.Mailer, service.TplManager)
	service.InitPasswordRecoverer(
		service.Logger,
		service.PasswordHasher,
		service.RepositoryManager.User,
		service.RepositoryManager.PasswordRecovery,
		service.PasswordRecoveryMailer,
	)

	router := httprouter.New()

	setupNotFoundRoute(router)
	setupStaticRoutes(router)
	setupWebRoutes(router)

	host := service.Config.Server.Host
	port := service.Config.Server.Port
	tls := service.Config.Server.TLS

	service.Logger.WithFields(logrus.Fields{
		"tls":  tls,
		"host": host,
		"port": port,
	}).Info("HTTP(S) server is going to start.")
	if tls {
		service.Logger.Fatal(http.ListenAndServeTLS(
			host+":"+port,
			service.Config.Server.CertFile,
			service.Config.Server.KeyFile,
			router,
		))
	} else {
		service.Logger.Fatal(http.ListenAndServe(host+":"+port, router))
	}
}
예제 #2
0
파일: init_db.go 프로젝트: escribano/charon
func initDBCommandAction(context *cli.Context) {
	service.InitConfig(context.GlobalString("environment"))
	service.InitLogger(service.Config.Logger)
	service.InitDB(service.Config.DB)

	queryBytes, err := ioutil.ReadFile("data/sql/schema_" + service.Config.DB.Adapter + ".sql")
	if err != nil {
		service.Logger.Fatal(err)
	}

	service.Logger.Info("Schema file opened successfully.")

	_, err = service.DBPool.Exec(string(queryBytes))
	if err != nil {
		service.Logger.Fatal(err)
	}

	service.Logger.Info("Database has been initialized successfully.")
}