package main import ( "context" "log/slog" "net/http" "os" "os/signal" "git.t-juice.club/torjus/alerttonotify/bus" "git.t-juice.club/torjus/alerttonotify/server" ) const Version = "v0.1.0" func main() { // Setup logging logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{ Level: slog.LevelDebug, })) logger.Info("Starting alerttonotify", "version", Version) // Setup dbus connection nbus, err := bus.NewNotifyBus() if err != nil { logger.Error("Failed to create notify bus", "error", err) os.Exit(1) } defer nbus.Close() // Verify connection and server info, err := nbus.ServerInfo() if err != nil { logger.Error("Failed to get notification server info", "error", err) os.Exit(1) return } logger.Info("Connected to notification daemon", "server", info.Name, "version", info.Version) shutdownCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() // Setup http server srv := server.NewServer(nbus, logger) srv.Addr = ":5001" // Listen for shutdown signal go func() { <-shutdownCtx.Done() srv.Shutdown(context.Background()) }() logger.Info("Starting http server", "addr", srv.Addr) if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { logger.Error("Failed to start http server", "error", err) os.Exit(1) } logger.Info("Shutting down") }