diff --git a/main.go b/main.go index 3204cf6..b4a0cd8 100644 --- a/main.go +++ b/main.go @@ -40,25 +40,29 @@ func run(c context.Context, getEnv func(string) string) error { ctx, cancel := signal.NotifyContext(c, os.Interrupt) defer cancel() + // init sentry if err := sentry.Init(sentry.ClientOptions{ Dsn: getEnv("SENTRY_DSN"), EnableTracing: true, TracesSampleRate: 1.0, ProfilesSampleRate: 1.0, }); err != nil { - return fmt.Errorf("error initializing sentry: %s", err) + return fmt.Errorf("error initializing sentry %s", err) } + // init database db, err := gorm.Open(postgres.Open(getEnv("DATABASE_URL")), &gorm.Config{}) if err != nil { return fmt.Errorf("error connecting to the database %s", err) } + // build booking service err = db.AutoMigrate(&booking.Booking{}, &booking.BookingRequest{}, &booking.Item{}) if err != nil { return fmt.Errorf("error migrating the database %s", err) } + // build pdf service ps, err := pdf.NewPdfService( getEnv("HTMLDOCS_PROJECT_ID"), getEnv("HTMLDOCS_REPORT_PROJECT_ID"), @@ -69,23 +73,28 @@ func run(c context.Context, getEnv func(string) string) error { return fmt.Errorf("error starting pdf service %s", err) } - as, err := auth.NewService(getEnv("SESSION_SECRET"), getEnv("ADMIN"), getEnv("ADMIN_SECRET")) + // build authentication service + as, err := auth.NewService( + getEnv("SESSION_SECRET"), + getEnv("ADMIN"), + getEnv("ADMIN_SECRET"), + ) if err != nil { return fmt.Errorf("error starting auth service %s", err) } - creds := os.Getenv("CALENDAR_CREDENTIALS") - t2Id := os.Getenv("CALENDAR_ID_T2") - t3Id := os.Getenv("CALENDAR_ID_T3") - - cs, err := calendar.NewService(ctx, creds, - calendar.WithCalendar("T2", t2Id), - calendar.WithCalendar("T3", t3Id), + // build calendar service + cs, err := calendar.NewService( + ctx, + getEnv("CALENDAR_CREDENTIALS"), + calendar.WithCalendar("T2", getEnv("CALENDAR_ID_T2")), + calendar.WithCalendar("T3", getEnv("CALENDAR_ID_T3")), ) if err != nil { - log.Fatalf("cannot build calendar service: %s", err) + log.Fatalf("error starting calendar service %s", err) } + // starting server p := getEnv("PORT") port, err := strconv.Atoi(p) if err != nil {