1 Star 0 Fork 0

mooncake/orange

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
start.go 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
mooncake 提交于 2024-10-17 22:42 . update
package start
import (
"fmt"
"log/slog"
"gitee.com/achilles2018/orange/cmd/com"
"gitee.com/achilles2018/orange/common/codes"
"gitee.com/achilles2018/orange/common/global"
"gitee.com/achilles2018/orange/common/middleware"
stackUtil "gitee.com/achilles2018/orange/common/utils/stack"
"github.com/mooncake9527/npx/core"
"github.com/mooncake9527/npx/core/ebus"
"github.com/mooncake9527/npx/core/i18n"
"github.com/spf13/cobra"
_ "github.com/spf13/viper/remote"
)
var (
configYml string
Cmd = &cobra.Command{
Use: "start",
Short: "start application with config file",
Example: "eg. orange start -c resources/config.yaml",
Run: func(cmd *cobra.Command, args []string) {
defer func() {
if err := recover(); err != nil {
slog.Error("panic err " + fmt.Sprintf("%v", err) + " \r\n stack:" + stackUtil.GetStack())
}
}()
startApplication()
},
}
)
func init() {
Cmd.PersistentFlags().StringVarP(&configYml, "config", "c", "resources/config.dev.yaml", "start server with provided configuration file")
}
func startApplication() {
com.Pre(configYml)
ebus.EventBus.Publish(global.TopicCoreInitFinish)
i18n.Register(&codes.Code{
EnableI18N: core.Cfg.Server.I18n,
Lang: core.Cfg.Server.Lang,
})
r := core.GetGinEngine()
middleware.InitMiddleware(r, &core.Cfg)
for _, f := range AppRouters {
f()
}
go func() {
<-core.Started
startedInit()
}()
go func() {
<-core.ToClose
ebus.EventBus.Publish(global.TopicApplicationClose)
toClose()
}()
core.Run()
slog.Info("server exited")
}
func startedInit() {
if core.Cfg.GrpcServer.Enable {
grpcInit()
}
rdInit()
slog.Debug("server started")
}
func toClose() {
if core.Cfg.GrpcServer.Enable {
closeGrpc()
}
rdRelease()
slog.Debug("release resources")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/achilles2018/orange.git
git@gitee.com:achilles2018/orange.git
achilles2018
orange
orange
48fb7be20f63

搜索帮助

0d507c66 1850385 C8b1a773 1850385