diff --git a/database/database.go b/database/database.go index 79b8ed2..405316b 100644 --- a/database/database.go +++ b/database/database.go @@ -174,13 +174,17 @@ func (db SqlDatabase) AddImage(uuid string, name string, alt string) (err error) } func MakeSqlConnection(user string, password string, address string, port int, database string) (SqlDatabase, error) { - /// Checking the DB connection + /// TODO : let user specify the DB connection_str := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", user, password, address, port, database) db, err := sql.Open("mysql", connection_str) if err != nil { return SqlDatabase{}, err } + + if err := db.Ping(); err != nil { + return SqlDatabase{}, err + } // See "Important settings" section. db.SetConnMaxLifetime(time.Second * 5) db.SetMaxOpenConns(10)