From 80a0260021463499204e42e9b2fac5eb00273f1b Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Fri, 2 Jun 2023 02:44:11 -0400 Subject: [PATCH] Ajouter data.NewDataClientFromViper() --- data/data.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/data/data.go b/data/data.go index 4572dea..9601792 100644 --- a/data/data.go +++ b/data/data.go @@ -7,6 +7,7 @@ import ( "git.agecem.com/agecem/bottin/v4/models" _ "github.com/jackc/pgx/stdlib" "github.com/jmoiron/sqlx" + "github.com/spf13/viper" ) // DataClient is a postgres client based on sqlx @@ -24,6 +25,19 @@ type PostgresConnection struct { SSL bool } +func NewDataClientFromViper() (*DataClient, error) { + client, err := NewDataClient( + PostgresConnection{ + User: viper.GetString("db.user"), + Password: viper.GetString("db.password"), + Host: viper.GetString("db.host"), + Database: viper.GetString("db.database"), + Port: viper.GetInt("db.port"), + }) + + return client, err +} + func NewDataClient(connection PostgresConnection) (*DataClient, error) { client := &DataClient{PostgresConnection: connection}