From 6da09baa85ba96e72562fb3c1956711d167a4efb Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 7 Nov 2019 13:40:58 +0100 Subject: db values using env vars --- src/db.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/db.go b/src/db.go index 22ab1a8..300e559 100644 --- a/src/db.go +++ b/src/db.go @@ -4,13 +4,22 @@ import ( "database/sql" "fmt" "log" + "os" + "strconv" _ "github.com/lib/pq" ) // setup the Database func setupDatabase() (*sql.DB, error) { - connStr := "host=postgresql port=5432 user=postgres dbname=postgres sslmode=disable" + + dbHost := os.Getenv("DBHOST") + dbPort, _ := strconv.Atoi(os.Getenv("DBPORT")) + dbUser := os.Getenv("DBUSER") + dbName := os.Getenv("DBNAME") + + //connStr := "host=postgresql port=5432 user=postgres dbname=postgres sslmode=disable" + connStr := fmt.Sprintf("host=%s port=%d user=%s dbname=%s sslmode=disable", dbHost, dbPort, dbUser, dbName) // open a connection to the database db, err := sql.Open("postgres", connStr) -- cgit 1.4.1