1 Star 0 Fork 0

后端组/mvc

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
irisStarter.go 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
heweiosc 提交于 2020-04-21 03:34 +08:00 . add redis servide
package starters
import (
"gitee.com/nuokwan_backend_group/mvc/Base"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/logger"
"github.com/kataras/iris/v12/middleware/recover"
)
const DefAppPort = "8080"
const AppConfigScope = "app"
const AppPortTag = "app.port"
const AppInitHookTag = "hooks.AppInit"
type AppInitHook func(*iris.Application, Base.ICtxContainer)
type IrisStarter struct {
Engine *iris.Application
Ctx Base.ICtxContainer
}
func NewIrisStarter() Base.IStarter {
return &IrisStarter{Engine: NewIrisApp()}
}
func NewIrisApp() *iris.Application {
app := iris.New()
return app
}
func (i *IrisStarter) Init() {
if i.Engine == nil {
i.Engine = NewIrisApp()
}
i.Ctx = Base.AppContext()
i.Engine.Use(recover.New())
i.Engine.Use(logger.New())
i.Engine.Logger().SetLevel("debug")
// 获取初始化钩子函数
i.execAppInitHook()
// 注册
i.Register(i.Ctx)
}
// 执行 AppInit hooks
func (i *IrisStarter) execAppInitHook() {
var hook = i.Ctx.Get(AppInitHookTag)
if hook != nil {
switch hook.(type) {
case AppInitHook:
handler := hook.(AppInitHook)
handler(i.Engine, i.Ctx)
case []AppInitHook:
handlers := hook.([]AppInitHook)
for _, handler := range handlers {
handler(i.Engine, i.Ctx)
}
}
}
}
func (i *IrisStarter) Start() {
var (
err error
port = Base.Config().GetDefault(AppPortTag, DefAppPort)
)
err = i.Engine.Run(iris.Addr(":"+port), iris.WithoutServerError(iris.ErrServerClosed))
Base.OnError(err)
}
func (i *IrisStarter) Stop() {
Base.Log().Info("app stop...")
}
func (i *IrisStarter) Register(ctx Base.ICtxContainer) {
ctx.RegisterBySingle("app", i)
}
func (i *IrisStarter) Block() bool {
return true
}
func (i *IrisStarter) Destroy() {
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nuokwan_backend_group/mvc.git
git@gitee.com:nuokwan_backend_group/mvc.git
nuokwan_backend_group
mvc
mvc
1bf86c47ef7b

搜索帮助