package http import ( "cs-bridge/internal/config" "cs-bridge/internal/http/handlers" "cs-bridge/internal/http/middleware" "cs-bridge/internal/oauth" "cs-bridge/pkg/logger" "fmt" "net/http" "github.com/go-chi/chi/v5" ) type Router struct { r http.Handler cfg config.Server } func NewRouter(cfg *config.Config, mgr *oauth.Manager) *Router { r := chi.NewRouter() r.Get("/health", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok")) }) r.Get("/", handlers.Entry(&cfg.CodeServer)) r.Get("/oauth/{provider}", handlers.OauthLogin(mgr)) r.Get("/oauth/{provider}/callback", handlers.OauthCallBack(mgr)) // Git准备相关路由 - 需要登录 r.With(middleware.RequireLogin).Get("/tz", handlers.GitProgressPage()) r.Get("/ws/git-progress", handlers.GitProgressWS()) r.Post("/api/git/execute", handlers.ExecuteGitOperations(cfg)) return &Router{ r: r, cfg: cfg.Server, } } func (r *Router) ListenAndServe() { logger.GetLogger().Info(fmt.Sprintf("server is running as: http://localhost:%d", r.cfg.Port)) http.ListenAndServe(fmt.Sprintf(":%d", r.cfg.Port), r.r) }