Ajouter data.NewDataClientFromViper()
This commit is contained in:
parent
4673612e06
commit
80a0260021
1 changed files with 14 additions and 0 deletions
14
data/data.go
14
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}
|
||||
|
||||
|
|
Loading…
Reference in a new issue