diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2025-01-17 13:21:24 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2025-01-17 13:21:24 +0000 |
| commit | c00b690bd6f600554a1404e692bd9e4373325d27 (patch) | |
| tree | 4488b625e1c24af52fced6f60ac1b3ddff1383bc /main.go | |
Initial commit
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -0,0 +1,59 @@ +package main + +import ( + "fmt" + "log/slog" + "os" + + "github.com/LMBishop/confplanner/api" + config "github.com/LMBishop/confplanner/internal" + "github.com/LMBishop/confplanner/pkg/database" + "github.com/LMBishop/confplanner/pkg/favourites" + "github.com/LMBishop/confplanner/pkg/schedule" + "github.com/LMBishop/confplanner/pkg/user" +) + +func main() { + if err := run(); err != nil { + slog.Error("Unhandled error", "error", err) + os.Exit(1) + } +} + +func run() error { + c := &config.Config{} + err := config.ReadConfig("config.yaml", c) + if err != nil { + return fmt.Errorf("failed to load config: %w", err) + } + + pool, err := database.Connect(c.Database.ConnString) + if err != nil { + return fmt.Errorf("failed to connect to database: %w", err) + } + + if err := database.Migrate(pool); err != nil { + return fmt.Errorf("database migration failed: %w", err) + } + + userService := user.NewService(pool, c.AcceptRegistrations) + favouritesService := favourites.NewService(pool) + scheduleService, err := schedule.NewService(c.Conference.ScheduleURL) + if err != nil { + return fmt.Errorf("failed to create schedule service: %w", err) + } + + app := api.NewServer(api.ApiServices{ + UserService: userService, + FavouritesService: favouritesService, + ScheduleService: scheduleService, + }) + + slog.Info("Server is listening", "host", c.Server.Host, "port", c.Server.Port) + + if err := app.Listen(fmt.Sprintf("%s:%s", c.Server.Host, c.Server.Port)); err != nil { + return fmt.Errorf("failed to start server: %w", err) + } + + return nil +} |
