ovpn-certman/services/db.go

27 lines
462 B
Go
Raw Normal View History

2018-01-26 14:49:03 +01:00
package services
import (
"log"
"git.klink.asia/paul/certman/models"
"git.klink.asia/paul/certman/settings"
"github.com/jinzhu/gorm"
)
var DB *gorm.DB
func InitDB() *gorm.DB {
dsn := settings.Get("DATABASE_URL", "db.sqlite3")
// Establish connection
db, err := gorm.Open("sqlite3", dsn)
if err != nil {
log.Fatalf("Could not open database: %s", err.Error())
}
// Migrate models
db.AutoMigrate(models.User{}, models.ClientConf{})
return db
}