代码拉取完成,页面将自动刷新
package app
import (
"fmt"
sldefine "gitee.com/simplexyz/simplego/log"
sutil "gitee.com/simplexyz/simplego/util"
"sync"
"github.com/spf13/viper"
sactor "gitee.com/simplexyz/simplego/actor"
sadefine "gitee.com/simplexyz/simplego/actor/define"
sahttpreq "gitee.com/simplexyz/simplego/actor/http/request"
sahttpsvr "gitee.com/simplexyz/simplego/actor/http/server"
satimer "gitee.com/simplexyz/simplego/actor/timer"
)
type App struct {
config *viper.Viper
startedWg sync.WaitGroup
stoppedWg sync.WaitGroup
pid *sadefine.PID
logger sldefine.ILogger
timerMgr *satimer.Manager
httpRequestMgr *sahttpreq.Manager
httpServer *sahttpsvr.Server
}
func Create(configPath string) (*App, error) {
a := &App{
config: viper.New(),
}
// todo 加载配置
a.config.SetConfigName(sutil.MustGetProgramFileBaseName())
a.config.SetConfigType("json")
a.config.AddConfigPath(configPath)
err := a.config.ReadInConfig()
if err != nil {
return nil, fmt.Errorf("read config file fail, %w", err)
}
return a, nil
}
func (a *App) WaitForStopped() {
a.stoppedWg.Wait()
}
func (a *App) onStarted(ctx sadefine.Context) {
a.pid = ctx.Self().Clone()
a.logger = sactor.GetLogger(ctx, true)
a.timerMgr = sactor.GetTimerManager(ctx)
a.httpRequestMgr = sahttpreq.NewManager(sactor.RootContext(), a.pid, a.logger)
// todo 根据配置文件决定要不要启动http server
}
func (a *App) onStopped(ctx sadefine.Context) {
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。