mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
47 lines
937 B
Go
47 lines
937 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/rjNemo/rentease/config"
|
|
"github.com/rjNemo/rentease/internal/booking"
|
|
"github.com/rjNemo/rentease/internal/pdf"
|
|
"github.com/rjNemo/rentease/internal/server"
|
|
)
|
|
|
|
//go:embed assets
|
|
var static embed.FS
|
|
|
|
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)
|
|
}
|
|
|
|
ps, err := pdf.NewPdfService()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
server.New(&static, booking.NewService(db), ps, config.NewHost()).Start()
|
|
}
|