Documentation
¶
Index ¶
- func AdjustAppInfo(ai *conf.AppInfo)
- func BeDaemon(arg string)
- func NewApp(ctx *Context, srv ...transport.Server) *kratos.App
- func NewAppInfo(appId, version, appName *string) *conf.AppInfo
- func NewAppName(project, appId string) string
- func NewInstanceId(project, appId, version, host string) string
- func NewRootCmd(f *CommandFlags, runE func(cmd *cobra.Command, args []string) error) *cobra.Command
- func ResolveHost() string
- func RunApp(ctx *Context, initApp InitAppFunc, opts ...func(root *cobra.Command)) error
- type CommandFlags
- type Context
- func (c *Context) CancelContext()
- func (c *Context) Context() context.Context
- func (c *Context) DeleteCustomConfig(key string)
- func (c *Context) GetAppInfo() *conf.AppInfo
- func (c *Context) GetConfig() *conf.Bootstrap
- func (c *Context) GetCustomConfig(key string) (any, bool)
- func (c *Context) GetLogger() kratosLog.Logger
- func (c *Context) GetRegistrar() kratosRegistry.Registrar
- func (c *Context) GetValue(key string) (interface{}, bool)
- func (c *Context) NewLoggerHelper(moduleName string) *kratosLog.Helper
- func (c *Context) PrintAppInfo()
- func (c *Context) RangeCustomConfig(fn func(key string, val any) bool)
- func (c *Context) RegisterCustomConfig(key string, cfg proto.Message)
- func (c *Context) SetCustomConfig(key string, cfg proto.Message)
- func (c *Context) SetValue(key string, val interface{})
- func (c *Context) UpTime() time.Duration
- type InitAppFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewInstanceId ¶
NewInstanceId 生成实例ID 格式:project-appId-version@host@xid
func NewRootCmd ¶
NewRootCmd 创建根命令并绑定命令行参数和执行函数。
func ResolveHost ¶
func ResolveHost() string
ResolveHost 返回优先级选择的 host 标识:POD_NAME -> HOSTNAME env -> os.Hostname() -> 首个非 loopback IPv4 -> "unknown-host"
Types ¶
type CommandFlags ¶
type CommandFlags struct {
Conf string // 引导配置文件路径,默认为:../../configs
Env string // 开发环境:dev、debug……
ConfigHost string // 远程配置服务端地址
ConfigType string // 远程配置服务端类型
Daemon bool // 是否转为守护进程
}
CommandFlags 命令传参
func NewCommandFlags ¶
func NewCommandFlags() *CommandFlags
func (*CommandFlags) AddFlags ¶
func (f *CommandFlags) AddFlags(cmd *cobra.Command)
AddFlags 将 flags 绑定到传入的 cobra.Command(通常是 root command)。
func (*CommandFlags) Init ¶
func (f *CommandFlags) Init()
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context 引导上下文
func NewContext ¶
NewContext 创建带 cancel 的应用级 Context(传 nil 使用 Background)
func NewContextWithParam ¶
func (*Context) DeleteCustomConfig ¶
DeleteCustomConfig 删除自定义配置
func (*Context) GetAppInfo ¶
func (*Context) GetCustomConfig ¶
GetCustomConfig 获取自定义配置(原始类型)
func (*Context) GetRegistrar ¶
func (c *Context) GetRegistrar() kratosRegistry.Registrar
func (*Context) NewLoggerHelper ¶
func (*Context) PrintAppInfo ¶
func (c *Context) PrintAppInfo()
func (*Context) RangeCustomConfig ¶
RangeCustomConfig 遍历自定义配置,回调返回 false 可停止遍历
func (*Context) RegisterCustomConfig ¶
RegisterCustomConfig 注册自定义配置
func (*Context) SetCustomConfig ¶
SetCustomConfig 存入自定义配置
Click to show internal directories.
Click to hide internal directories.