mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-12 12:09:56 +01:00
30 lines
626 B
Go
30 lines
626 B
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"github.com/go-sql-driver/mysql"
|
|
"github.com/twofas/2fas-server/config"
|
|
)
|
|
|
|
func NewDbConnection(conf config.Configuration) *sql.DB {
|
|
cfg := &mysql.Config{
|
|
Net: "tcp",
|
|
Addr: fmt.Sprintf("%v:%v", conf.Db.Host, conf.Db.Port),
|
|
DBName: conf.Db.Database,
|
|
User: conf.Db.Username,
|
|
Passwd: conf.Db.Password,
|
|
AllowNativePasswords: true,
|
|
ParseTime: true,
|
|
MultiStatements: true,
|
|
}
|
|
|
|
conn, err := sql.Open("mysql", cfg.FormatDSN())
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return conn
|
|
}
|