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")) // 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 }