about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-11-07 13:40:58 +0100
committerEmile <hanemile@protonmail.com>2019-11-07 13:40:58 +0100
commit6da09baa85ba96e72562fb3c1956711d167a4efb (patch)
tree26789a184aef89000563dc85294ca534fb199915 /src
parentd5b4b45e883d605a6443422b9c956308d64e969e (diff)
db values using env vars
Diffstat (limited to 'src')
-rw-r--r--src/db.go11
1 files changed, 10 insertions, 1 deletions
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)