bootstrap

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 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 Defaulter, call ApplyDefaults (even when scan was skipped, so optional-missing still gets literal defaults).
  3. 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 聚合启动阶段产物与资源清理句柄。

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 定义服务实例身份信息。

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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