You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
867 B
48 lines
867 B
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)
|
|
}
|
|
|