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