mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(server): implement management endpoints and redis sync
Enable full resource management via API and support data plane synchronization. - Add CRUD handlers for Providers, Models, and Keys using DTOs - Implement LogWriter service for asynchronous, batched audit logging - Update SyncService to snapshot full configuration state to Redis - Register new API routes and initialize background services - Add configuration options for logging performance tuning
This commit is contained in:
@@ -57,13 +57,22 @@ func main() {
|
||||
log.Println("Connected to PostgreSQL successfully")
|
||||
|
||||
// Auto Migrate
|
||||
if err := db.AutoMigrate(&model.User{}, &model.Provider{}, &model.Key{}, &model.Model{}); err != nil {
|
||||
if err := db.AutoMigrate(&model.User{}, &model.Provider{}, &model.Key{}, &model.Model{}, &model.LogRecord{}); err != nil {
|
||||
log.Fatalf("Failed to auto migrate: %v", err)
|
||||
}
|
||||
|
||||
// 4. Setup Services and Handlers
|
||||
syncService := service.NewSyncService(rdb)
|
||||
handler := api.NewHandler(db, syncService)
|
||||
logWriter := service.NewLogWriter(db, cfg.Log.QueueCapacity, cfg.Log.BatchSize, cfg.Log.FlushInterval)
|
||||
logCtx, cancelLogs := context.WithCancel(context.Background())
|
||||
defer cancelLogs()
|
||||
logWriter.Start(logCtx)
|
||||
handler := api.NewHandler(db, syncService, logWriter)
|
||||
|
||||
// 4.1 Prime Redis snapshots so DP can start with data
|
||||
if err := syncService.SyncAll(db); err != nil {
|
||||
log.Printf("Initial sync warning: %v", err)
|
||||
}
|
||||
|
||||
// 5. Setup Gin Router
|
||||
r := gin.Default()
|
||||
@@ -74,7 +83,12 @@ func main() {
|
||||
})
|
||||
|
||||
// API Routes
|
||||
r.POST("/providers", handler.CreateProvider)
|
||||
r.POST("/keys", handler.CreateKey)
|
||||
r.POST("/models", handler.CreateModel)
|
||||
r.GET("/models", handler.ListModels)
|
||||
r.POST("/sync/snapshot", handler.SyncSnapshot)
|
||||
r.POST("/logs", handler.IngestLog)
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: ":" + cfg.Server.Port,
|
||||
|
||||
Reference in New Issue
Block a user