Example #1
0
File: api.go Project: carrot/burrow
func main() {
	// ---------------------------
	// Setting Active Environment
	// ---------------------------

	if len(os.Args) > 1 {
		err := environment.Set(os.Args[1])
		if err != nil {
			log.Fatal(err)
		}
	} else {
		log.Fatal("Running requires an environment argument")
	}

	// ---------
	// Database
	// ---------

	db.Open()
	defer db.Close()

	// -----
	// Echo
	// -----

	e := request.BuildEcho()

	// ----
	// Run
	// ----

	port := environment.GetEnvVar(environment.PORT)
	log.Println("Server started on :" + port)
	graceful.ListenAndServe(e.Server(":"+port), 5*time.Second) // Graceful shutdown
}
Example #2
0
func Open() {
	// Pulling environment vars
	databaseUrl := environment.GetEnvVar(environment.PSQL_DATABASE_URL)

	// Opening + storing the connection
	db, err := sql.Open("postgres", databaseUrl)
	if err != nil {
		log.Fatal(err)
	}

	// Pinging the database
	err = db.Ping()
	if err != nil {
		log.Fatal(err)
	}

	database = db
}
Example #3
0
func (suite *ApiTestSuite) SetupTest() {
	// Loading .env file.  We're not failing here in the
	// event that the .env file can't be loaded. The
	// project might be running through a CI system
	// and the environment variables.  Will fail later
	// rather than early
	environment.SetWithRelativeDirectory("../", environment.TESTING)

	// Starting database
	db.Open()

	// Getting our Echo instance
	e := BuildEcho()

	// Running the server
	port := environment.GetEnvVar(environment.PORT)
	suite.wreckerClient = wrecker.New("http://localhost:" + port)
	log.Println("Server started on :" + port)
	go graceful.ListenAndServe(e.Server(":"+port), 5*time.Second) // Graceful shutdown
}