27 lines
449 B
Go
27 lines
449 B
Go
|
package slowtwitch
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"fmt"
|
||
|
_ "github.com/go-sql-driver/mysql"
|
||
|
)
|
||
|
|
||
|
func Connect(user, pass, url, port, dbName string) (*sql.DB, error) {
|
||
|
connectionString := user + ":" + pass + "@tcp(" + url + ":" + port + ")/" + dbName
|
||
|
|
||
|
db, err := sql.Open("mysql", connectionString)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
err = db.Ping()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
fmt.Println("Successfully connected!")
|
||
|
|
||
|
return db, nil
|
||
|
}
|