feat: v0.3.1 — Go/Gin 后端重写 + gh-ost 集成
架构变更: - Python/FastAPI → Go/Gin 重写(Python 后端保留在 backend-python/) - GORM + SQLite(兼容现有数据库表结构) - JWT 认证 + RBAC 权限中间件 Go 后端结构: - cmd/server/main.go — 入口,端口 9000 - config/config.go — 环境变量配置 - internal/model/ — GORM 模型(30张表,完全兼容 SQLite) - internal/handler/ — auth/instance/ticket/dashboard/ghost handler - internal/middleware/ — JWT 认证 + CORS - internal/ghost/ — gh-ost 集成模块(同步/异步执行,任务管理) - router/router.go — API 路由注册(/api/v1/...) gh-ost 集成: - RunGhOst() 同步执行 - RunGhOstAsync() 异步执行 + 进度追踪 - TaskManager 管理多个并发任务 - API: POST /ghost/dry-run, /ghost/execute, GET /ghost/status/:taskId 核心 API 已对齐: - POST /auth/login (JWT) - GET /dashboard/stats, /dashboard/my-tickets - GET /tickets/statistics, CRUD + approve/execute - GET/POST/PUT/DELETE /instances - GET /users, /audit-rules, /announcements, /settings 已验证: - 登录 admin/admin123 ✅ - Dashboard 99工单/110查询/4实例 ✅ - 工单统计按角色过滤 ✅
This commit is contained in:
1 parent
43d1f3a234
commit
ca308e277d
202 files changed
+2265
-51181
No files matched your search
@@ -0,0 +1,81 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"sql-platform/internal/handler"
|
||||
"sql-platform/internal/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Setup(r *gin.Engine) {
|
||||
api := r.Group("/api/v1")
|
||||
|
||||
// Public routes
|
||||
api.POST("/auth/login", handler.Login)
|
||||
|
||||
// Authenticated routes
|
||||
auth := api.Group("")
|
||||
auth.Use(middleware.AuthMiddleware())
|
||||
{
|
||||
// Auth
|
||||
auth.GET("/auth/me", handler.GetMe)
|
||||
|
||||
// Dashboard
|
||||
auth.GET("/dashboard/stats", handler.DashboardStats)
|
||||
auth.GET("/dashboard/my-tickets", handler.MyTickets)
|
||||
|
||||
// Tickets
|
||||
auth.GET("/tickets/statistics", handler.TicketStatistics)
|
||||
auth.GET("/tickets", handler.ListTickets)
|
||||
auth.GET("/tickets/:id", handler.GetTicket)
|
||||
auth.POST("/tickets", handler.CreateTicket)
|
||||
auth.POST("/tickets/:id/approve", handler.ApproveTicket)
|
||||
auth.POST("/tickets/:id/execute", handler.ExecuteTicket)
|
||||
|
||||
// Instances
|
||||
auth.GET("/instances", handler.ListInstances)
|
||||
auth.GET("/instances/stats", handler.InstanceStats)
|
||||
auth.GET("/instances/:id", handler.GetInstance)
|
||||
auth.POST("/instances/:id/test-connection", handler.TestConnection)
|
||||
|
||||
// Instance management (admin/dba only)
|
||||
admin := auth.Group("")
|
||||
admin.Use(middleware.RequireRole("admin", "dba"))
|
||||
{
|
||||
admin.POST("/instances", handler.CreateInstance)
|
||||
admin.PUT("/instances/:id", handler.UpdateInstance)
|
||||
admin.DELETE("/instances/:id", handler.DeleteInstance)
|
||||
}
|
||||
|
||||
// Users (admin only)
|
||||
userAdmin := auth.Group("")
|
||||
userAdmin.Use(middleware.RequireRole("admin"))
|
||||
{
|
||||
userAdmin.GET("/users", handler.ListUsers)
|
||||
userAdmin.POST("/users", handler.CreateUser)
|
||||
userAdmin.PUT("/users/:id", handler.UpdateUser)
|
||||
userAdmin.DELETE("/users/:id", handler.DeleteUser)
|
||||
}
|
||||
|
||||
// gh-ost (admin/dba only)
|
||||
ghostGroup := auth.Group("")
|
||||
ghostGroup.Use(middleware.RequireRole("admin", "dba"))
|
||||
{
|
||||
ghostGroup.POST("/ghost/dry-run", handler.GhOstDryRun)
|
||||
ghostGroup.POST("/ghost/execute", handler.GhOstExecute)
|
||||
ghostGroup.GET("/ghost/status/:taskId", handler.GhOstStatus)
|
||||
ghostGroup.GET("/ghost/tasks", handler.GhOstListTasks)
|
||||
}
|
||||
|
||||
// Read-only resources
|
||||
auth.GET("/audit-rules", handler.ListAuditRules)
|
||||
auth.GET("/announcements", handler.ListAnnouncements)
|
||||
auth.GET("/query-histories", handler.ListQueryHistories)
|
||||
auth.GET("/settings", handler.ListSettings)
|
||||
auth.GET("/notifications/channels", handler.ListNotificationChannels)
|
||||
auth.GET("/notifications/templates", handler.ListNotificationTemplates)
|
||||
auth.GET("/workflows", handler.ListWorkflows)
|
||||
auth.GET("/instance-groups", handler.ListInstanceGroups)
|
||||
auth.POST("/notifications/test", handler.TestNotification)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user