Skip to content

Commit

Permalink
add auth repository && add initpostgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyKomarovCoder committed Sep 28, 2023
1 parent 9dead8e commit d9dfee1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions internal/db/postgresql/postgresql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dsn

import (
"fmt"
"os"

"github.com/joho/godotenv"
)

type PostgresConfig struct {
DBHost string
DBPort string
DBUser string
DBName string
DBPassword string
DBSSLMode string
}

func InitPostgresConfigFromEnv() (PostgresConfig, error) {
var cfg = PostgresConfig{}
if err := godotenv.Load(); err != nil {
return cfg, err
}

host, existHost := os.LookupEnv("DB_HOST")
port, existPort := os.LookupEnv("DB_PORT")
user, existUser := os.LookupEnv("DB_USER")
pass, existPass := os.LookupEnv("DB_PASS")
dbname, existName := os.LookupEnv("DB_NAME")
dbsslmode, existSSL := os.LookupEnv("DB_SSLMODE")

if !existHost || !existPort || !existUser || !existPass || !existName || existSSL {
return cfg, fmt.Errorf("existHost or existPort or existUser or existPass or existName is Empty")
}
cfg = PostgresConfig{
DBHost: host,
DBPort: port,
DBUser: user,
DBName: dbname,
DBPassword: pass,
DBSSLMode: dbsslmode,
}
return cfg, nil
}

// TO DO InitPostgresDB()

0 comments on commit d9dfee1

Please sign in to comment.