package server import ( "fmt" "log/slog" "net/http" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" slogchi "github.com/samber/slog-chi" "go.fifitido.net/ytdl-web/pkg/serverctx" ) func ListenAndServe(options ...Option) error { opts := DefaultOptions() for _, opt := range options { opt(opts) } r := chi.NewRouter() r.Use( serverctx.Middleware, middleware.RequestID, middleware.RealIP, slogchi.New(opts.Logger), middleware.Recoverer, ) r.Group(Routes) listenAddr := fmt.Sprintf("%s:%d", opts.ListenAddr, opts.ListenPort) opts.Logger.Info("Starting HTTP server", slog.String("addr", opts.ListenAddr), slog.Int("port", opts.ListenPort)) return http.ListenAndServe(listenAddr, r) }