27 lines
553 B
Go
27 lines
553 B
Go
|
package app
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
)
|
||
|
|
||
|
// MyDB is the MySQL handler variable
|
||
|
var MyDB *sql.DB
|
||
|
|
||
|
// InitDB initializes the MySQL database using DSN information from the config file
|
||
|
func InitDB() {
|
||
|
var db *sql.DB
|
||
|
var err error
|
||
|
if GetDBMS() == "mysql" {
|
||
|
db, err = sql.Open("mysql", GetDSN())
|
||
|
} else {
|
||
|
sugar.Fatalf("app.InitDB: 💣 ⛔ unknown DBMS: %s", GetDBMS())
|
||
|
return
|
||
|
}
|
||
|
if err != nil {
|
||
|
sugar.Fatalf("app.InitDB: 💣 ⛔ Can't log on to DBMS host: %w", err)
|
||
|
return
|
||
|
}
|
||
|
MyDB = db
|
||
|
sugar.Debugf("app.InitDB: 👍 📤 %s", GetDBMS())
|
||
|
}
|