package controller import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" ) // RegisterRoutes 注册所有路由 func RegisterRoutes(s *ghttp.Server) { // API v1 路由组 v1 := s.Group("/api/v1") // 公开API路由 - 不需要认证 public := v1.Group("/public") { // 网站配置 public.GET("/configs", Config.Public) // 文章相关 articles := public.Group("/articles") { articles.GET("/", Article.List) articles.GET("/{id}", Article.Detail) } // 新闻相关 news := public.Group("/news") { news.GET("/", News.List) news.GET("/{id}", News.Detail) } } // 用户API路由 user := v1.Group("/user") { user.POST("/login", User.Login) user.POST("/register", User.Create) user.GET("/profile", User.Detail) user.PUT("/profile", User.Update) } // 管理员API路由 admin := v1.Group("/admin") { // 管理员认证 admin.POST("/login", Admin.Login) admin.POST("/logout", Admin.Logout) admin.GET("/profile", Admin.Detail) admin.PUT("/profile", Admin.Update) // 用户管理 users := admin.Group("/users") { users.GET("/", User.List) users.POST("/", User.Create) users.GET("/{id}", User.Detail) users.PUT("/{id}", User.Update) users.DELETE("/{id}", User.Delete) } // 文章管理 articles := admin.Group("/articles") { articles.GET("/", Article.List) articles.POST("/", Article.Create) articles.GET("/{id}", Article.Detail) articles.PUT("/{id}", Article.Update) articles.DELETE("/{id}", Article.Delete) } // 新闻管理 news := admin.Group("/news") { news.GET("/", News.List) news.POST("/", News.Create) news.GET("/{id}", News.Detail) news.PUT("/{id}", News.Update) news.DELETE("/{id}", News.Delete) } // 附件管理 attachments := admin.Group("/attachments") { attachments.GET("/", Attachment.List) attachments.POST("/upload", Attachment.Upload) attachments.GET("/{id}", Attachment.Detail) attachments.DELETE("/{id}", Attachment.Delete) } // 系统配置管理 configs := admin.Group("/configs") { configs.GET("/", Config.List) configs.PUT("/{id}", Config.Update) } } // 健康检查 s.BindHandler("/health", func(r *ghttp.Request) { r.Response.WriteJson(g.Map{ "status": "ok", "message": "CMS API服务运行正常", }) }) }