示例#1
0
// Serve runs the webserver
func Serve(cfg *config.Config) {

	log := configureLogger()

	db := database.MustConnect(cfg)
	defer db.Close()

	mailer, err := mailer.New(cfg)

	if err != nil {
		panic(err)
	}

	handler := server.New(db, mailer, log, cfg).Configure()

	if err := http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), handler); err != nil {
		panic(err)
	}

}
示例#2
0
// Serve runs the webserver
func Serve(cfg *config.Config) {

	log := logrus.New()

	log.Formatter = &logrus.TextFormatter{
		FullTimestamp: true,
		ForceColors:   true,
	}

	log.Info("Starting web service...")

	db := database.MustConnect(cfg)
	defer db.Close()

	mailer, err := mailer.New(
		cfg.Mail.Addr,
		smtp.PlainAuth(
			cfg.Mail.ID,
			cfg.Mail.User,
			cfg.Mail.Password,
			cfg.Mail.Host,
		),
		"./templates/email",
	)

	if err != nil {
		panic(err)
	}

	handler := server.New(db, mailer, log, cfg).Handler()

	if err := http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), handler); err != nil {
		panic(err)
	}

}