1 Star 0 Fork 0

xlizy / common-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bootstrap.go 854 Bytes
一键复制 编辑 原始数据 按行查看 历史
xlizy 提交于 2024-04-14 14:48 . save
package bootstrap
import (
stdContext "context"
"gitee.com/xlizy/common-go/base/config"
"gitee.com/xlizy/common-go/components/nacos/v2"
"gitee.com/xlizy/common-go/utils/snowflake"
"gitee.com/xlizy/common-go/utils/zlog"
"github.com/kataras/iris/v12"
"os"
"os/signal"
"syscall"
"time"
)
func Init() {
zlog.InitLogger(config.GetLogCfg().Path)
snowflake.Init(1, 1)
zlog.Info("项目开始启动...")
nacos.InitNacos()
}
// GracefulShutdown 优雅关闭
func GracefulShutdown(app *iris.Application) {
// 等待中断信号以优雅地关闭服务器
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
// 阻塞,直到接收到信号
<-stop
// 创建一个5秒的超时上下文
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), 15*time.Second)
defer cancel()
_ = app.Shutdown(ctx)
}
Go
1
https://gitee.com/xlizy/common-go.git
git@gitee.com:xlizy/common-go.git
xlizy
common-go
common-go
v0.2.2

搜索帮助