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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"sql-platform/config"
|
||||
"sql-platform/internal/middleware"
|
||||
"sql-platform/internal/model"
|
||||
"sql-platform/router"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load config
|
||||
config.Init()
|
||||
|
||||
if !config.C.Debug {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
// Connect to SQLite
|
||||
db, err := gorm.Open(sqlite.Open(config.C.DBPath), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to connect to database: %v", err)
|
||||
}
|
||||
model.DB = db
|
||||
|
||||
// Auto-migrate (add missing tables/columns, won\'t drop existing data)
|
||||
_ = db.AutoMigrate(
|
||||
&model.User{},
|
||||
&model.Instance{},
|
||||
&model.Ticket{},
|
||||
&model.TicketApproval{},
|
||||
&model.TicketSQLItem{},
|
||||
&model.AuditRule{},
|
||||
&model.AuditLog{},
|
||||
&model.QueryHistory{},
|
||||
&model.WorkflowDefinition{},
|
||||
&model.WorkflowStep{},
|
||||
&model.WorkflowVersion{},
|
||||
&model.WorkflowExecutionLog{},
|
||||
&model.Announcement{},
|
||||
&model.InstanceGroup{},
|
||||
&model.InstanceGroupMember{},
|
||||
&model.LDAPConfig{},
|
||||
&model.NotificationChannel{},
|
||||
&model.NotificationTemplate{},
|
||||
&model.SystemSetting{},
|
||||
&model.OperationLog{},
|
||||
&model.MaskingRule{},
|
||||
&model.Backup{},
|
||||
&model.SchemaRevision{},
|
||||
&model.SlowLog{},
|
||||
&model.ScheduledTask{},
|
||||
&model.ScheduledTaskLog{},
|
||||
&model.UserGroup{},
|
||||
)
|
||||
|
||||
// Setup Gin
|
||||
r := gin.Default()
|
||||
r.Use(middleware.CORSMiddleware())
|
||||
|
||||
// Health check
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"status": "ok", "version": "0.3.1", "backend": "go"})
|
||||
})
|
||||
|
||||
// Routes
|
||||
router.Setup(r)
|
||||
|
||||
// Start server
|
||||
addr := fmt.Sprintf(":%s", config.C.Port)
|
||||
log.Printf("SQL Platform Go backend starting on %s", addr)
|
||||
if err := r.Run(addr); err != nil {
|
||||
log.Fatalf("Failed to start server: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user