Exemplo n.º 1
0
func startServer() {
	bindAddress := env.String("ADDRESS", ":8080")

	log.Printf("Starting server on %s\n", bindAddress)

	if err := http.ListenAndServe(bindAddress, setupRouter()); err != nil {
		log.Fatalf("Can't start server: %v", err)
	}
}
Exemplo n.º 2
0
func connectDB() {
	var err error

	info := env.String("DB_INFO", "dbname=demo sslmode=disable")
	db, err = gorm.Open("postgres", info)
	try(err)
	try(db.DB().Ping())

	db.Exec("CREATE SEQUENCE code_seq START 3364") // = 58*58
	codeSeq, err = db.DB().Prepare("SELECT nextval('code_seq')")
	try(err)
}
Exemplo n.º 3
0
func initDB(resetConfirmation bool) {
	var err error

	connectionString := env.String("DB_CONN", "dbname=shorty_dev sslmode=disable")

	db, err = sql.Open("postgres", connectionString)
	checkErr(err)

	db.SetMaxOpenConns(10)
	db.SetMaxIdleConns(5)

	if env.Bool("RESET_DB", false) {
		if resetConfirmation {
			confirmDbReset()
		}
		initDBSchema()
	}

	prepareDbQueries()
}