2016-11-21 12:24:50 +00:00
|
|
|
package core
|
2016-11-19 21:35:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
_"github.com/go-sql-driver/mysql"
|
2016-11-21 12:24:50 +00:00
|
|
|
"log"
|
2016-11-19 21:35:23 +00:00
|
|
|
)
|
|
|
|
|
2016-11-21 12:24:50 +00:00
|
|
|
var DB *sql.DB
|
2016-11-19 21:35:23 +00:00
|
|
|
|
2016-11-21 12:24:50 +00:00
|
|
|
func SetupDatabaseConnection() *sql.DB {
|
2016-11-19 21:35:23 +00:00
|
|
|
// setup db connection
|
|
|
|
var err error
|
2016-11-21 12:24:50 +00:00
|
|
|
DB, err = sql.Open("mysql", "root:root@/ana")
|
2016-11-19 21:35:23 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error()) // Just for example purpose. You should use proper error handling instead of panic
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open doesn't open a connection. Validate DSN data:
|
2016-11-21 12:24:50 +00:00
|
|
|
err = DB.Ping()
|
2016-11-19 21:35:23 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error()) // proper error handling instead of panic in your app
|
|
|
|
}
|
2016-11-21 12:24:50 +00:00
|
|
|
|
|
|
|
return DB
|
2016-11-19 21:35:23 +00:00
|
|
|
}
|