skyview/main.go
Ole-Morten Duesund 8ce4f4c397 Initial implementation of SkyView - ADS-B aircraft tracker
- Go application with embedded static files for dump1090 frontend
- TCP client for SBS-1/BaseStation format (port 30003)
- Real-time WebSocket updates with aircraft tracking
- Modern web frontend with Leaflet maps and mobile-responsive design
- Aircraft table with filtering/sorting and statistics dashboard
- Origin configuration for receiver location and distance calculations
- Automatic config.json loading from current directory
- Foreground execution by default with optional -daemon flag

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 22:09:37 +02:00

69 lines
No EOL
1.4 KiB
Go

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)
}
}
}