代码拉取完成,页面将自动刷新
同步操作将从 distill/distill-infra 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package infra
import (
conf "gitee.com/banyanhouse/distill-infra/config"
log "github.com/sirupsen/logrus"
"reflect"
)
//应用程序
type BootApplication struct {
IsTest bool
conf *conf.TomlConfig
starterCtx StarterContext
}
//构造系统
func New(conf *conf.TomlConfig) *BootApplication {
e := &BootApplication{conf: conf, starterCtx: StarterContext{}}
e.starterCtx.SetProps(conf)
return e
}
func (b *BootApplication) Start() {
//1. 初始化starter
b.init()
//2. 安装starter
b.setup()
//3. 启动starter
b.start()
}
//程序初始化
func (e *BootApplication) init() {
log.Info("Initializing starters...")
for _, v := range GetStarters() {
typ := reflect.TypeOf(v)
log.Debugf("Initializing: PriorityGroup=%d,Priority=%d,type=%s", v.PriorityGroup(), v.Priority(), typ.String())
v.Init(e.starterCtx)
}
}
//程序安装
func (e *BootApplication) setup() {
log.Info("Setup starters...")
for _, v := range GetStarters() {
typ := reflect.TypeOf(v)
log.Debug("Setup: ", typ.String())
v.Setup(e.starterCtx)
}
}
//程序开始运行,开始接受调用
func (e *BootApplication) start() {
log.Info("Starting starters...")
for i, v := range GetStarters() {
typ := reflect.TypeOf(v)
log.Debug("Starting: ", typ.String())
if e.starterCtx.Props().App.Testing {
go v.Start(e.starterCtx)
continue
}
if v.StartBlocking() {
// 如果是阻塞的Start
// 最后一个的阻塞式Start,让其阻塞执行
if i+1 == len(GetStarters()) {
v.Start(e.starterCtx)
} else {
// 其余非最后一个,则启动协程执行
go v.Start(e.starterCtx)
}
} else {
// 非阻塞式Start则可以直接运行加载
v.Start(e.starterCtx)
}
}
}
//程序开始运行,开始接受调用
func (e *BootApplication) Stop() {
log.Info("Stoping starters...")
for _, v := range GetStarters() {
typ := reflect.TypeOf(v)
log.Debug("Stoping: ", typ.String())
v.Stop(e.starterCtx)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。