20 lines
303 B
Go
20 lines
303 B
Go
|
package initializers
|
||
|
|
||
|
import (
|
||
|
"gorm.io/driver/mysql"
|
||
|
"gorm.io/gorm"
|
||
|
"log"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
var DB *gorm.DB
|
||
|
|
||
|
func ConnectToDB() {
|
||
|
dsn := os.Getenv("DSN")
|
||
|
var err error
|
||
|
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||
|
if err != nil {
|
||
|
log.Fatal("Could not connect to database:\n" + err.Error())
|
||
|
}
|
||
|
}
|