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 Defaulter
- type OptionalSection
- type Runtime
- type Section
- type SvcIdentity
- type Validator
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 Defaulter, call ApplyDefaults (even when scan was skipped, so optional-missing still gets literal defaults).
- If section implements Validator, call Validate. The first non-nil error stops the iteration.
Returns nil when every section completed steps 1-3 without error.
Types ¶
type BootstrapOption ¶
type BootstrapOption func(*bootstrapOptions)
BootstrapOption 配置启动行为的可选项。
func WithEnvPrefix ¶
func WithEnvPrefix() BootstrapOption
WithEnvPrefix 启用环境变量前缀。 启用后,配置加载器会根据服务名推导前缀(如 iam.service → IAM_), 仅读取带前缀的环境变量覆盖配置。 默认不使用前缀,直接读取无前缀的环境变量。
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 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)`.
type SvcIdentity ¶
SvcIdentity 定义服务实例身份信息。
type Validator ¶ added in v0.6.0
type Validator interface {
ValidateConf() error
}
Validator is the contract for messages that carry required-field rules. The returned error is propagated verbatim from ScanSections — fail-fast on the first failing section, no further sections are processed.
The method is named ValidateConf (not Validate) to avoid colliding with the Validate() method that protoc-gen-validate generates on every message.