Exemple #1
0
func main() {
	// Initialize app.
	lib.InitSession()
	app.InitDB()
	defer app.CloseDB()

	// Routing.
	n := negroni.Classic()
	r := route()
	n.UseHandler(r)

	port := fmt.Sprintf(":%v", app.EnvOrElse("TODO_PORT", "3000"))

	// Try to run on HTTPS.
	cert := os.Getenv("TODO_CERT_PATH")
	key := os.Getenv("TODO_KEY_PATH")
	if cert != "" && key != "" {
		log.Printf("Running on port %s", port)
		if err := http.ListenAndServeTLS(port, cert, key, n); err != nil {
			log.Fatalf("Could not start server: %v", err)
		}
		os.Exit(0)
	}

	// Falling back to normal HTTP.
	log.Printf("Warning: this server does not use a safe connection!")
	n.Run(port)
}
Exemple #2
0
// Initialize the database before running an unit test.
func initTestDB() {
	lib.InitSession()
	lib.ViewsDir = "../views"

	app.InitDB()

	if err := app.Db.TruncateTables(); err != nil {
		log.Fatalf("Could not initialize DB: %v", err)
	}
}
Exemple #3
0
// Initialize the database before running an unit test.
func initTestDB() {
	log.SetOutput(ioutil.Discard)

	lib.InitSession()
	lib.ViewsDir = "../views"

	_ = os.Setenv("TODO_ENV", "test")
	InitDB()

	_ = Db.TruncateTables()
}