topic/cleaning #4

Merged
shah merged 23 commits from topic/cleaning into master 2022-05-31 14:53:59 +00:00
2 changed files with 22 additions and 24 deletions
Showing only changes of commit 69a1fd6070 - Show all commits

1
go.mod
View file

@ -3,7 +3,6 @@ module domain/genityapp
go 1.14
require (
github.com/joho/godotenv v1.3.0
github.com/lib/pq v1.8.0
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
)

View file

@ -3,8 +3,6 @@ package app
import (
"database/sql"
"fmt"
"github.com/joho/godotenv"
"log"
"os"
)
@ -41,34 +39,35 @@ func CloseDB() {
Db.Close()
}
// return the value of the key
func goDotEnvVariable(key string) string {
// load .env file
pwd, _ := os.Getwd()
err := godotenv.Load(pwd + "/configs/web.env")
if err != nil {
log.Fatalf(err.Error())
}
return os.Getenv(key)
}
func dbConfig() map[string]string {
conf := make(map[string]string)
user := goDotEnvVariable(dbuser)
host := goDotEnvVariable(dbhost)
port := goDotEnvVariable(dbport)
pass := goDotEnvVariable(dbpass)
databaseNname := goDotEnvVariable(dbname)
host, ok := os.LookupEnv(dbhost)
if !ok {
panic("DBHOST environment variable required but not set")
}
port, ok := os.LookupEnv(dbport)
if !ok {
panic("DBPORT environment variable required but not set")
}
user, ok := os.LookupEnv(dbuser)
if !ok {
panic("DBUSER environment variable required but not set")
}
password, ok := os.LookupEnv(dbpass)
if !ok {
panic("DBPASS environment variable required but not set")
}
name, ok := os.LookupEnv(dbname)
if !ok {
panic("DBNAME environment variable required but not set")
}
conf[dbhost] = host
conf[dbport] = port
conf[dbuser] = user
conf[dbpass] = pass
conf[dbname] = databaseNname
conf[dbpass] = password
conf[dbname] = name
return conf
}