Fixed small typo, replaced DB connection details in Makefile by .env loading

This commit is contained in:
Paulo Truta
2021-02-17 12:10:15 +01:00
parent b04e854fdd
commit 59707b8abd
6 changed files with 60 additions and 30 deletions
+24
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"log"
"os/exec"
"github.com/joho/godotenv"
)
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
@@ -35,3 +37,25 @@ func DeleteEmptySlices(s []string) []string {
}
return r
}
// GetMySQLDbConnectionDetails : Returns the necessary string as connection info for SQL.db()
func GetMySQLDbConnectionDetails() string {
// const apiEnvFileLocation = "/home/system/components/api/edgebox.env"
const apiEnvFileLocation = "/home/jpt/Repositories/edgebox/api/edgebox.env"
var apiEnv map[string]string
apiEnv, err := godotenv.Read(apiEnvFileLocation)
if err != nil {
log.Fatal("Error loading .env file")
}
Dbhost := "127.0.0.1:" + apiEnv["HOST_MACHINE_MYSQL_PORT"]
Dbname := apiEnv["MYSQL_DATABASE"]
Dbuser := apiEnv["MYSQL_USER"]
Dbpass := apiEnv["MYSQL_PASSWORD"]
return Dbuser + ":" + Dbpass + "@tcp(" + Dbhost + ")/" + Dbname
}