master
parent
dae105d15f
commit
4c71e83a5e
@ -0,0 +1,27 @@
|
||||
package lib
|
||||
|
||||
import(
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
"github.com/joho/godotenv"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
||||
func Connector() (*gorm.DB, error) {
|
||||
// Database connection string
|
||||
err:= godotenv.Load();
|
||||
if(err!=nil) {
|
||||
log.Fatal("Error loading .env file")
|
||||
}
|
||||
dsn := fmt.Sprint(os.Getenv("DATABASE_DSN"))
|
||||
log.Print(dsn)
|
||||
// Open the database connection
|
||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatal("failed to connect database:", err)
|
||||
}
|
||||
return db, err
|
||||
}
|
Loading…
Reference in new issue