chore: update id order
This commit is contained in:
@@ -22,32 +22,26 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Forcer la timezone Europe/Paris (UTC+1/+2)
|
||||
if loc, err := time.LoadLocation("Europe/Paris"); err == nil {
|
||||
time.Local = loc
|
||||
} else {
|
||||
log.Printf("⚠️ Impossible de charger la timezone Europe/Paris: %v", err)
|
||||
}
|
||||
|
||||
// Chargement des variables d'environnement
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("⚠️ Aucun fichier .env trouvé, utilisation des valeurs par défaut.")
|
||||
}
|
||||
|
||||
// Initialisation de la base de données
|
||||
database := db.InitDB()
|
||||
defer database.Close()
|
||||
log.Printf("✅ Database initialisée: %+v", database)
|
||||
// Initialisation de Redis
|
||||
db.InitRedis()
|
||||
defer db.Redis.Close()
|
||||
log.Println("✅ Redis initialisé avec succès")
|
||||
|
||||
// Initialisation du service de géolocalisation
|
||||
geoService := services.NewGeoService(db.Redis, db.RedisCtx)
|
||||
log.Println("✅ Service de géolocalisation initialisé")
|
||||
|
||||
// Initialisation du service Telegram
|
||||
telegramService := services.NewTelegramService()
|
||||
if telegramService.IsConfigured() {
|
||||
log.Println("✅ Service Telegram initialisé")
|
||||
@@ -60,15 +54,12 @@ func main() {
|
||||
log.Println("ℹ️ Service Telegram désactivé (TELEGRAM_BOT_TOKEN non défini)")
|
||||
}
|
||||
|
||||
// Migration: ajout des colonnes telegram_chat_id
|
||||
database.MigrateAddTelegramColumns()
|
||||
|
||||
// Priorité DB > .env pour la config Telegram
|
||||
if dbSettings, err := database.GetSettings(); err == nil {
|
||||
telegramService.Reload(dbSettings.TelegramBotToken, dbSettings.TelegramBotUsername)
|
||||
if dbSettings.TelegramBotToken != "" {
|
||||
log.Printf("✅ [TELEGRAM] Config chargée depuis la DB (username: %s)", dbSettings.TelegramBotUsername)
|
||||
// Enregistrer le webhook si l'URL est configurée (et pas déjà fait depuis l'env)
|
||||
if webhookURL := os.Getenv("TELEGRAM_WEBHOOK_URL"); webhookURL != "" {
|
||||
if err := telegramService.SetWebhook(webhookURL); err != nil {
|
||||
log.Printf("⚠️ [TELEGRAM] Erreur enregistrement webhook (DB reload): %v", err)
|
||||
@@ -77,9 +68,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 🧹 NETTOYAGE INITIAL DES COMMANDES INVALIDES
|
||||
// ============================================
|
||||
log.Println("")
|
||||
log.Println("🧹 Démarrage du nettoyage des commandes invalides...")
|
||||
removed, err := database.CleanupInvalidQueueCommands()
|
||||
@@ -93,32 +81,21 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 🔄 DÉMARRAGE DU SCHEDULER DE NETTOYAGE AUTO
|
||||
// ============================================
|
||||
go database.StartQueueCleanupScheduler()
|
||||
log.Println("✅ Scheduler de nettoyage démarré (toutes les 5 min)")
|
||||
|
||||
// ============================================
|
||||
// 🔄 SYNCHRONISATION DES STATUTS LIVREURS
|
||||
// ============================================
|
||||
if err := database.SyncAllDeliverymanStatuses(); err != nil {
|
||||
log.Printf("⚠️ Erreur synchronisation statuts: %v", err)
|
||||
} else {
|
||||
log.Println("✅ Synchronisation des statuts livreurs terminée")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// ⭐ DÉMARRAGE DU CRON JOB AUTO-ASSIGNATION
|
||||
// ============================================
|
||||
go workers.StartAutoAssignmentCron(database, geoService)
|
||||
log.Println("✅ Cron job auto-assignation démarré (5 min)")
|
||||
|
||||
// Démarrage des workers Redis en arrière-plan
|
||||
go workers.StartRedisWorkers(database)
|
||||
log.Println("✅ Workers Redis démarrés")
|
||||
|
||||
// Worker de vérification des paiements crypto (recharge les clés dynamiquement)
|
||||
workers.StartDynamicPaymentChecker(database, func() *services.NowPaymentsClient {
|
||||
s, err := database.GetSettings()
|
||||
if err != nil || !s.CryptoPaymentEnabled || s.NowPaymentsAPIKey == "" {
|
||||
@@ -130,7 +107,6 @@ func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
r := gin.Default()
|
||||
|
||||
// Configuration des sessions
|
||||
store := cookie.NewStore([]byte(os.Getenv("SESSION_SECRET")))
|
||||
store.Options(sessions.Options{
|
||||
Path: "/",
|
||||
@@ -142,7 +118,6 @@ func main() {
|
||||
})
|
||||
r.Use(sessions.Sessions("mysession", store))
|
||||
|
||||
// Configuration CORS
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"https://uber-stup.club", "https://5.181.0.112.nip.io", "https://5.181.0.112.nip.io:8080", "https://5.181.0.112.nip.io:8443", "https://mln-uber.club", "http://localhost:5173", "http://5.181.0.112"},
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"},
|
||||
@@ -151,7 +126,6 @@ func main() {
|
||||
AllowCredentials: true,
|
||||
}))
|
||||
|
||||
// Middleware pour injecter la base de données et geoService
|
||||
r.Use(func(c *gin.Context) {
|
||||
c.Set("database", database)
|
||||
c.Set("geoService", geoService)
|
||||
@@ -167,12 +141,8 @@ func main() {
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Fichiers statiques
|
||||
r.Static("/uploads", "./uploads")
|
||||
|
||||
// ============================================
|
||||
// ENREGISTRER TOUTES LES ROUTES
|
||||
// ============================================
|
||||
routes.SetupRoutes(r, database, geoService)
|
||||
|
||||
if err := r.Run(":8080"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user