building database connection string from config file

This commit is contained in:
farhan 2020-12-12 05:50:43 +00:00
parent 10013323ef
commit 9e2af34c15

View File

@ -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)
}