package service import ( "net/http" "git.umbrella.haus/ae/notatest/internal/data" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/jackc/pgx/v5" "github.com/rs/zerolog/log" ) func Run(conn *pgx.Conn, q *data.Queries, jwtSecret string) error { r := chi.NewRouter() authRouter := authResource{ JWTSecret: jwtSecret, Users: q, Tokens: q, } notesRouter := notesResource{ JWTSecret: jwtSecret, Notes: q, } // Global middlewares r.Use(middleware.RequestID) r.Use(middleware.RealIP) r.Use(loggerMiddleware(&log.Logger)) r.Use(middleware.Recoverer) r.Use(middleware.AllowContentType("application/json")) // Routes grouped by functionality (we must prefix the API routes with `/api` // as the domain will be the same for the front and back ends) r.Route("/api", func(r chi.Router) { r.Mount("/auth", authRouter.Routes()) r.Mount("/notes", notesRouter.Routes()) }) log.Info().Msg("Starting server on :8080") return http.ListenAndServe(":8080", r) }