2026-03-15 18:17:39 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"os"
|
|
|
|
|
|
"os/signal"
|
|
|
|
|
|
"syscall"
|
|
|
|
|
|
"time"
|
2026-03-17 00:47:17 +08:00
|
|
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
2026-03-15 18:17:39 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
// 初始化应用程序(Wire 自动生成)
|
|
|
|
|
|
app, err := InitializeApp()
|
|
|
|
|
|
if err != nil {
|
2026-03-17 00:47:17 +08:00
|
|
|
|
zap.L().Fatal("failed to initialize app",
|
|
|
|
|
|
zap.Error(err),
|
|
|
|
|
|
)
|
2026-03-15 18:17:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 启动应用程序
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
if err := app.Start(ctx); err != nil {
|
2026-03-17 00:47:17 +08:00
|
|
|
|
app.Logger.Fatal("failed to start app",
|
|
|
|
|
|
zap.Error(err),
|
|
|
|
|
|
)
|
2026-03-15 18:17:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 优雅关闭
|
|
|
|
|
|
quit := make(chan os.Signal, 1)
|
|
|
|
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
<-quit
|
|
|
|
|
|
|
|
|
|
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
|
|
if err := app.Stop(shutdownCtx); err != nil {
|
2026-03-17 00:47:17 +08:00
|
|
|
|
app.Logger.Error("Error during shutdown",
|
|
|
|
|
|
zap.Error(err),
|
|
|
|
|
|
)
|
2026-03-15 18:17:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|