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 the database:\n" + err.Error()) } }