代码拉取完成,页面将自动刷新
package bootstrap
import (
"fmt"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
kratosRegistry "github.com/go-kratos/kratos/v2/registry"
"github.com/go-kratos/kratos/v2/transport"
"gitee.com/ssxlt/kratos-bootstrap/config"
"gitee.com/ssxlt/kratos-bootstrap/logger"
"gitee.com/ssxlt/kratos-bootstrap/registry"
"gitee.com/ssxlt/kratos-bootstrap/tracer"
conf "gitee.com/ssxlt/kratos-bootstrap/api/gen/go/conf/v1"
)
var (
Service = config.NewServiceInfo(
"",
"1.0.0",
"",
)
)
// NewApp 创建应用程序
func NewApp(ll log.Logger, rr kratosRegistry.Registrar, srv ...transport.Server) *kratos.App {
return kratos.New(
kratos.ID(Service.GetInstanceId()),
kratos.Name(Service.Name),
kratos.Version(Service.Version),
kratos.Metadata(Service.Metadata),
kratos.Logger(ll),
kratos.Server(
srv...,
),
kratos.Registrar(rr),
)
}
// DoBootstrap 执行引导
func DoBootstrap(serviceInfo *config.ServiceInfo) (*conf.Bootstrap, log.Logger, kratosRegistry.Registrar) {
// inject command flags
Flags := config.NewCommandFlags()
Flags.Init()
var err error
// load configs
if err = config.LoadBootstrapConfig(Flags.Conf); err != nil {
panic(fmt.Sprintf("load config failed: %v", err))
}
// init logger
ll := logger.NewLoggerProvider(config.GetBootstrapConfig().Logger, serviceInfo)
// init registrar
reg := registry.NewRegistry(config.GetBootstrapConfig().Registry)
// init tracer
if err = tracer.NewTracerProvider(config.GetBootstrapConfig().Trace, serviceInfo); err != nil {
panic(fmt.Sprintf("init tracer failed: %v", err))
}
return config.GetBootstrapConfig(), ll, reg
}
type InitApp func(logger log.Logger, registrar kratosRegistry.Registrar, bootstrap *conf.Bootstrap) (*kratos.App, func(), error)
// Bootstrap 应用引导启动
func Bootstrap(initApp InitApp, serviceName, version *string) {
if serviceName != nil && len(*serviceName) != 0 {
Service.Name = *serviceName
}
if version != nil && len(*version) != 0 {
Service.Version = *version
}
// bootstrap
cfg, ll, reg := DoBootstrap(Service)
// init app
app, cleanup, err := initApp(ll, reg, cfg)
if err != nil {
panic(err)
}
defer cleanup()
// run the app.
if err = app.Run(); err != nil {
panic(err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。