15 lines
380 B
Go
15 lines
380 B
Go
package config
|
|
|
|
import (
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func InitDB(config *Config) *gorm.DB {
|
|
db, err := gorm.Open(postgres.Open("host=" + config.DatabaseHost + " user=" + config.DatabaseUser + " password=" + config.DatabasePassword + " dbname=" + config.DatabaseName))
|
|
if err != nil {
|
|
Logger.Sugar().Fatalw("Fail to connect to database", err)
|
|
}
|
|
return db
|
|
}
|