topic/cleaning #4

Merged
shah merged 23 commits from topic/cleaning into master 2022-05-31 14:53:59 +00:00
4 changed files with 38 additions and 11 deletions
Showing only changes of commit 1ee48da79f - Show all commits

View file

@ -7,4 +7,6 @@ run: build
build-binary: build-binary:
GOOS=linux GOARCH=amd64 go build -o bins/genityapp -v cmd/* GOOS=linux GOARCH=amd64 go build -o bins/genityapp -v cmd/*
Dev-run: build-binary build run
.PHONY: build-binary run build .PHONY: build-binary run build

View file

@ -1,4 +1,4 @@
dbhost=${COMPOSE_PROJECT_NAME}_db_1 dbhost=genitywebapp_db_1
dbport=5432 dbport=5432
dbuser=root_user dbuser=root_user
dbpass=shahzad12 dbpass=shahzad12

1
go.mod
View file

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

View file

@ -3,14 +3,17 @@ package app
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/joho/godotenv"
"log"
"os"
) )
const ( const (
dbhost = "DBHOST" dbhost = "dbhost"
dbport = "DBPORT" dbport = "dbport"
dbuser = "DBUSER" dbuser = "dbuser"
dbpass = "DBPASS" dbpass = "dbpass"
dbname = "DBNAME" dbname = "dbname"
) )
var Db *sql.DB var Db *sql.DB
@ -38,12 +41,33 @@ func CloseDB() {
Db.Close() Db.Close()
} }
// return the value of the key
func goDotEnvVariable(key string) string {
// load .env file
err := godotenv.Load("/go/src/app/configs/web.env")
if err != nil {
log.Fatalf(err.Error())
}
return os.Getenv(key)
}
func dbConfig() map[string]string { func dbConfig() map[string]string {
conf := make(map[string]string) conf := make(map[string]string)
conf[dbhost] = "genitywebapp_db_1"
conf[dbport] = "5432" user := goDotEnvVariable(dbuser)
conf[dbuser] = "root_user" host := goDotEnvVariable(dbhost)
conf[dbpass] = "shahzad12" port := goDotEnvVariable(dbport)
conf[dbname] = "db_genity" pass := goDotEnvVariable(dbpass)
databaseNname := goDotEnvVariable(dbname)
conf[dbhost] = host
conf[dbport] = port
conf[dbuser] = user
conf[dbpass] = pass
conf[dbname] = databaseNname
return conf return conf
} }