From 741f16f88ec82657ed6ac9b68fbc524ae18167da Mon Sep 17 00:00:00 2001 From: dhax Date: Fri, 20 Sep 2024 02:07:51 +0200 Subject: [PATCH] use DB_DSN database connection string only --- database/postgres.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/database/postgres.go b/database/postgres.go index dc6be06..ffd0101 100644 --- a/database/postgres.go +++ b/database/postgres.go @@ -14,13 +14,9 @@ import ( // DBConn returns a postgres connection pool. func DBConn() (*bun.DB, error) { - viper.SetDefault("db_network", "tcp") - viper.SetDefault("db_addr", "localhost:5432") - viper.SetDefault("db_user", "postgres") - viper.SetDefault("db_password", "postgres") - viper.SetDefault("db_database", "postgres") + viper.SetDefault("db_dsn", "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable") - dsn := "postgres://" + viper.GetString("db_user") + ":" + viper.GetString("db_password") + "@" + viper.GetString("db_addr") + "/" + viper.GetString("db_database") + "?sslmode=disable" + dsn := viper.GetString("db_dsn") sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))