1 Star 0 Fork 0

xlizy/common-go

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
iris_util.go 868 Bytes
Copy Edit Raw Blame History
xlizy authored 2024-04-22 16:59 . 优化
package iris_util
import (
stdContext "context"
"gitee.com/xlizy/common-go/base/response"
"gitee.com/xlizy/common-go/utils/middleware"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"os"
"os/signal"
"syscall"
"time"
)
var _app *iris.Application
func init() {
// GracefulShutdown
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-signals
gracefulShutdown()
}()
}
func GetDefaultApp() *iris.Application {
_app = iris.New()
_app.UseRouter(middleware.GobalRecover, middleware.Default)
_app.Get("/actuator/health", func(ctx *context.Context) {
ctx.JSON(response.Succ())
})
return _app
}
// gracefulShutdown 优雅关闭
func gracefulShutdown() {
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), 15*time.Second)
defer cancel()
_ = _app.Shutdown(ctx)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xlizy/common-go.git
git@gitee.com:xlizy/common-go.git
xlizy
common-go
common-go
v0.2.10

Search