22 lines
302 B
Go
22 lines
302 B
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
|
|
"github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
func GetDatabaseFromConfig(config mysql.Config) *sql.DB {
|
|
db, err := sql.Open("mysql", config.FormatDSN())
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if err = db.Ping(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return db
|
|
}
|