From 9e2af34c1523c677ad75f233d4dba833ffc05da6 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Sat, 12 Dec 2020 05:50:43 +0000 Subject: [PATCH] building database connection string from config file --- engine/db.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/db.go b/engine/db.go index 9c18bd5..519b13a 100644 --- a/engine/db.go +++ b/engine/db.go @@ -4,6 +4,7 @@ import ( "github.com/jackc/pgx/pgxpool" "context" "log" + "fmt" ) func writePost(pool *pgxpool.Pool, reportpost ReportPost) { @@ -51,7 +52,8 @@ func writePost(pool *pgxpool.Pool, reportpost ReportPost) { func get_db_pool() (*pgxpool.Pool) { // Setup Database - pool, err := pgxpool.Connect(context.Background(), "postgres://postgres@127.0.0.1/fedilogue") + db_uri := fmt.Sprintf("postgres://%s:%s@%s:%d/fedilogue", settings.Database.Username, settings.Database.Password, settings.Database.Host, settings.Database.Port) + pool, err := pgxpool.Connect(context.Background(), db_uri) if err != nil { log.Fatal("Unable to connect to database:", err) }