package main import ( "context" "embed" "flag" "log" "net/http" "os" "os/signal" "syscall" "time" "skyview/internal/config" "skyview/internal/server" ) //go:embed static/* var staticFiles embed.FS func main() { daemon := flag.Bool("daemon", false, "Run as daemon (background process)") flag.Parse() cfg, err := config.Load() if err != nil { log.Fatalf("Failed to load configuration: %v", err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() srv := server.New(cfg, staticFiles, ctx) log.Printf("Starting skyview server on %s", cfg.Server.Address) log.Printf("Connecting to dump1090 SBS-1 at %s:%d", cfg.Dump1090.Host, cfg.Dump1090.DataPort) httpServer := &http.Server{ Addr: cfg.Server.Address, Handler: srv, } go func() { if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { log.Fatalf("Server failed to start: %v", err) } }() if *daemon { log.Printf("Running as daemon...") select {} } else { log.Printf("Press Ctrl+C to stop") sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) <-sigChan log.Printf("Shutting down...") cancel() shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second) defer shutdownCancel() if err := httpServer.Shutdown(shutdownCtx); err != nil { log.Printf("Server shutdown error: %v", err) } } }