mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
37 lines
772 B
Go
37 lines
772 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/rjNemo/rentease/internal/booking"
|
|
"github.com/rjNemo/rentease/internal/pdf"
|
|
"github.com/rjNemo/rentease/internal/server"
|
|
)
|
|
|
|
func init() {
|
|
if os.Getenv("ENV") != "PROD" {
|
|
err := godotenv.Load(".env")
|
|
if err != nil {
|
|
log.Fatalln("Error loading .env file")
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
|
|
if err != nil {
|
|
log.Fatalf("error connecting to the database %s\n", err)
|
|
}
|
|
|
|
err = db.AutoMigrate(&booking.Booking{}, &booking.Item{})
|
|
if err != nil {
|
|
log.Fatalf("error migrating the database %s\n", err)
|
|
}
|
|
|
|
server.New(booking.NewService(db), pdf.NewPdfService()).Start()
|
|
}
|