package main import ( "context" "ims/app" "ims/util/log" "os" "os/signal" "syscall" "zestack.dev/env" ) func main() { ctx, cancel := context.WithCancelCause(context.Background()) // 读取环境变量配置 if err := env.Init(); err != nil { cancel(err) log.Error("failed to initialize environ variables", "error", err) os.Exit(1) } // 启动应用 if err := app.Start(ctx); err != nil { cancel(err) log.Error("failed to start the application", "error", err) os.Exit(1) } // 监听信号 singleChannel := make(chan os.Signal, 1) signal.Notify(singleChannel, syscall.SIGINT, syscall.SIGTERM) select { case <-ctx.Done(): case <-singleChannel: } // 停止应用 if err := app.Stop(); err != nil { cancel(err) log.Error("failed to stop the application", "error", err) os.Exit(1) } cancel(context.Canceled) os.Exit(0) }