Documentation
¶
Index ¶
- func BootstrapAndRun(configPath, name, version string, builder appBuilder, opts ...BootstrapOption) error
- func ScanConf[T any](rt *Runtime) (*T, error)
- func ScanSections(rt *Runtime, sections ...Section) error
- type BootstrapOption
- type ConfApplier
- type Defaulter
- type OptionalSection
- type RequiredChecker
- type Runtime
- type Section
- type SvcIdentity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BootstrapAndRun ¶
func BootstrapAndRun(configPath, name, version string, builder appBuilder, opts ...BootstrapOption) error
BootstrapAndRun 对外暴露统一启动入口。
func ScanSections ¶ added in v0.6.0
ScanSections loads every provided section from the runtime's merged kratos config. For each section the sequence is:
- If section implements OptionalSection and the key is missing, skip the Value(key).Scan call. Otherwise scan; an error here is fatal.
- If section implements ConfApplier, call ApplyConf (the generated composite that runs CheckRequired → ApplyDefaults in canonical order).
Returns nil when every section completed steps 1-2 without error.
Types ¶
type BootstrapOption ¶
type BootstrapOption func(*bootstrapOptions)
BootstrapOption 配置启动行为的可选项。
func WithEnvPrefix ¶
func WithEnvPrefix() BootstrapOption
WithEnvPrefix 启用环境变量前缀。 启用后,配置加载器会根据服务名推导前缀(如 iam.service → IAM_), 仅读取带前缀的环境变量覆盖配置。 默认不使用前缀,直接读取无前缀的环境变量。
type ConfApplier ¶ added in v0.6.3
type ConfApplier interface {
ApplyConf() error
}
ConfApplier is the composite contract for messages processed by protoc-gen-servora-conf. It runs the full post-scan sequence (currently CheckRequired → ApplyDefaults) in a single call. The method is generated; the runtime does not encode capability knowledge — future plugin capabilities are automatically included.
type Defaulter ¶ added in v0.6.0
type Defaulter interface {
ApplyDefaults()
}
Defaulter is the contract for messages that carry literal defaults declared via `(servora.conf.v1.field) = { default: ... }`. ScanSections invokes it after a successful (or skipped-optional) Value(key).Scan.
type OptionalSection ¶ added in v0.6.0
type OptionalSection interface {
SectionOptional() bool
}
OptionalSection marks a Section whose absence from the config source is non-fatal. When SectionOptional() reports true and the key is missing, ScanSections skips Value(key).Scan but still invokes Defaulter so the receiver ends up populated with literal defaults.
type RequiredChecker ¶ added in v0.6.3
type RequiredChecker interface {
CheckRequired() error
}
RequiredChecker is the contract for messages that carry required-field rules. Typically consumed via ConfApplier; exposed for testing and direct use.
type Runtime ¶
type Runtime struct {
Bootstrap *corev1.Bootstrap
Config kconfig.Config
Identity SvcIdentity
Logger log.Logger
// contains filtered or unexported fields
}
Runtime 聚合启动阶段产物与资源清理句柄。
type Section ¶ added in v0.6.0
type Section interface {
// SectionKey returns the dotted key under which the section lives in the
// merged kratos config (e.g. "broker", "audit", "data.kafka").
SectionKey() string
}
Section is the contract implemented by configuration messages that opt into keyed scanning via bootstrap.ScanSections. Implementations are typically produced by protoc-gen-servora-conf from `(servora.conf.v1.section)`.