代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。