TheMathemagicians/sevenkeys/database/get_database.go

22 lines
302 B
Go
Raw Normal View History

2024-04-23 16:52:48 +00:00
package database
import (
"database/sql"
"log"
"github.com/go-sql-driver/mysql"
)
func GetDatabaseFromConfig(config mysql.Config) *sql.DB {
2024-04-23 16:52:48 +00:00
db, err := sql.Open("mysql", config.FormatDSN())
if err != nil {
log.Fatal(err)
}
if err = db.Ping(); err != nil {
log.Fatal(err)
}
return db
}