1 Star 0 Fork 0

simplexyz/simplego

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.go 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
李文建 提交于 2023-11-04 19:00 +08:00 . 持续完善
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) {
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/simplexyz/simplego.git
git@gitee.com:simplexyz/simplego.git
simplexyz
simplego
simplego
d62e3dcece80

搜索帮助