bootstrap

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

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 ScanConf

func ScanConf[T any](rt *Runtime) (*T, error)

ScanConf 从 Runtime 的合并配置中扫描配置。 泛型参数 T 可为业务 conf protobuf message 或任意可反序列化结构体。

func ScanSections added in v0.6.0

func ScanSections(rt *Runtime, sections ...Section) error

ScanSections loads every provided section from the runtime's merged kratos config. For each section the sequence is:

  1. If section implements OptionalSection and the key is missing, skip the Value(key).Scan call. Otherwise scan; an error here is fatal.
  2. 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 聚合启动阶段产物与资源清理句柄。

func (*Runtime) Close

func (r *Runtime) Close()

Close 释放 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

type SvcIdentity struct {
	Name     string
	Version  string
	ID       string
	Metadata map[string]string
}

SvcIdentity 定义服务实例身份信息。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL