package main import ( "flag" webapi "git.entr0py.de/garionion/catie/internal/api" "git.entr0py.de/garionion/catie/internal/config" "git.entr0py.de/garionion/catie/internal/ndi" "github.com/go-gst/go-glib/glib" "github.com/go-gst/go-gst/gst" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/rs/zerolog/pkgerrors" "net/http" "os" "time" ) func main() { zerolog.TimeFieldFormat = time.RFC1123Z consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC1123Z} log.Logger = log.Output(consoleWriter).With().Timestamp().Caller().Logger() // --- Configuration Loading --- configPath := flag.String("config", "config.toml", "Path to the configuration file") flag.Parse() cfg, err := config.LoadConfig(*configPath) if err != nil { log.Fatal().Err(err).Msgf("Failed to load configuration from %s", *configPath) } // --- Logging Setup --- if cfg.Debug { zerolog.SetGlobalLevel(zerolog.DebugLevel) } if log.Logger.GetLevel() == zerolog.DebugLevel { zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack } log.Debug().Interface("config", cfg).Msg("starting application") api := webapi.New() e := echo.New() e.HideBanner = true e.HidePort = true e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ LogURI: true, LogStatus: true, LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error { log.Info(). Str("URI", v.URI). Int("status", v.Status). Msg("request") return nil }, })) //e.Use(middleware.Recover()) e.Use(middleware.CORS()) e.GET("/health", func(c echo.Context) error { return c.JSON(http.StatusOK, map[string]interface{}{ "status": "ok", }) }) apiGroup := e.Group("/api/v1") api.RegisterRoutes(apiGroup) gst.Init(nil) mainLoop := glib.NewMainLoop(glib.MainContextDefault(), false) go mainLoop.Run() n := ndi.NewNDI() api.RegisterDeviceMonitor(n) /*gst, err := gstreamer.New(cfg.Pipeline, cfg.Outputs, cfg.Debug) if err != nil { log.Fatal().Err(err).Msg("Failed to create gstreamer") } if err := gst.Run(); err != nil { log.Fatal().Err(err).Msg("Failed to run gstreamer") wg.Done() }*/ log.Info().Str("address", cfg.ListenAddr).Msg("starting web server") if err := e.Start(cfg.ListenAddr); err != nil { log.Fatal().Err(err).Msg("web server failed") } }