Build generation and dockerfile changes
This commit is contained in:
parent
ede359bcd8
commit
1ee48da79f
2
Makefile
2
Makefile
|
@ -7,4 +7,6 @@ run: build
|
|||
build-binary:
|
||||
GOOS=linux GOARCH=amd64 go build -o bins/genityapp -v cmd/*
|
||||
|
||||
Dev-run: build-binary build run
|
||||
|
||||
.PHONY: build-binary run build
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
dbhost=${COMPOSE_PROJECT_NAME}_db_1
|
||||
dbhost=genitywebapp_db_1
|
||||
dbport=5432
|
||||
dbuser=root_user
|
||||
dbpass=shahzad12
|
||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ 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
|
||||
)
|
||||
|
|
|
@ -3,14 +3,17 @@ package app
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/joho/godotenv"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
dbhost = "DBHOST"
|
||||
dbport = "DBPORT"
|
||||
dbuser = "DBUSER"
|
||||
dbpass = "DBPASS"
|
||||
dbname = "DBNAME"
|
||||
dbhost = "dbhost"
|
||||
dbport = "dbport"
|
||||
dbuser = "dbuser"
|
||||
dbpass = "dbpass"
|
||||
dbname = "dbname"
|
||||
)
|
||||
|
||||
var Db *sql.DB
|
||||
|
@ -38,12 +41,33 @@ func CloseDB() {
|
|||
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 {
|
||||
|
||||
conf := make(map[string]string)
|
||||
conf[dbhost] = "genitywebapp_db_1"
|
||||
conf[dbport] = "5432"
|
||||
conf[dbuser] = "root_user"
|
||||
conf[dbpass] = "shahzad12"
|
||||
conf[dbname] = "db_genity"
|
||||
|
||||
user := goDotEnvVariable(dbuser)
|
||||
host := goDotEnvVariable(dbhost)
|
||||
port := goDotEnvVariable(dbport)
|
||||
pass := goDotEnvVariable(dbpass)
|
||||
databaseNname := goDotEnvVariable(dbname)
|
||||
|
||||
conf[dbhost] = host
|
||||
conf[dbport] = port
|
||||
conf[dbuser] = user
|
||||
conf[dbpass] = pass
|
||||
conf[dbname] = databaseNname
|
||||
return conf
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue