Documentation
¶
Overview ¶
Package build 在启动期按配置构造插件实例图。
Build 按 root id 构造一个类型化根实例;BuildInto 按目标 struct 填充多个扩展点。 Scaffold / ScaffoldYAML 从目标 struct 反向生成 BuildInto 配置,默认引用所有兼容插件。 包内会先编译装配计划,再按依赖顺序执行构造。 Collect 和 CollectInstances 可从 Result 中按类型筛选已构造实例。 WireContributions 和 WireSetter 可把贡献者实例后置装配到收集器,避免构建图循环依赖。 有贡献者但找不到可装配的收集器时返回 ErrNoContributionsCollector。 运行期不应再调用本包;使用方只使用已经构造好的实例。
Index ¶
- Variables
- func Collect[T any](result *Result) []T
- func GetByID[T any](result *Result, id string) (T, bool)
- func RequireByID[T any](result *Result, field, id string) (T, error)
- func Scaffold(target any, opts ScaffoldOptions) (map[string]any, error)
- func ScaffoldYAML(target any, opts ScaffoldOptions) ([]byte, error)
- func ValidatePlan(graph map[string]any, rootID string, want reflect.Type) error
- func WireContributions[Contributor, Collector any](result *Result, attach func(Collector, []Contributor) error) error
- func WireSetter[T any](result *Result) error
- type ContributionsSetter
- type Error
- type Instance
- type Result
- type ScaffoldOptions
- type Stage
- type TypedInstance
Constants ¶
This section is empty.
Variables ¶
var ErrNoContributionsCollector = errors.New("pluginkit wire: contributors found but no collector wired")
ErrNoContributionsCollector is returned when result contains contributors but WireSetter or WireContributions could not wire any non-nil collector.
Functions ¶
func RequireByID ¶
RequireByID 按实例 id 取出指定类型的值,并在不存在或类型不匹配时返回装配错误。
field 用于错误信息,例如 "workflow.steps[2]"。
func Scaffold ¶ added in v0.1.2
func Scaffold(target any, opts ScaffoldOptions) (map[string]any, error)
Scaffold 根据 target struct 的扩展点字段,自动生成 BuildInto 可接受的 plugins 配置。 slice 字段会包含所有兼容插件;单值字段默认选第一个兼容插件。 插件实例 id 默认使用 kind,冲突时追加 -2、-3。
func ScaffoldYAML ¶ added in v0.1.2
func ScaffoldYAML(target any, opts ScaffoldOptions) ([]byte, error)
ScaffoldYAML 根据 target struct 生成带注释的 YAML 配置。 单值字段存在多个兼容插件时,会在 use 行附加 default/alternatives 注释。
func ValidatePlan ¶
ValidatePlan 只执行 resolve / typecheck / deps 规划,不调用插件 New。
func WireContributions ¶ added in v0.1.1
func WireContributions[Contributor, Collector any]( result *Result, attach func(Collector, []Contributor) error, ) error
WireContributions collects every instance assignable to Contributor from result and calls attach once per non-nil instance assignable to Collector. When there are no contributors, attach is not called. When contributors exist but no collector is wired, ErrNoContributionsCollector is returned. nil result or attach is a no-op.
func WireSetter ¶ added in v0.1.1
WireSetter collects contributions of type T and calls SetContributions on every non-nil instance that implements ContributionsSetter[T]. When there are no contributors, SetContributions is not called. When contributors exist but no collector is wired, ErrNoContributionsCollector is returned. nil result is a no-op.
Types ¶
type ContributionsSetter ¶ added in v0.1.1
ContributionsSetter receives contributions of type T collected from result. Host frameworks can adopt this naming convention and wire with WireSetter.
type Result ¶
type Result struct {
Instances []Instance
}
Result 保存本次 Build 构造出的全部实例。
type ScaffoldOptions ¶ added in v0.1.2
ScaffoldOptions 控制从 target struct 生成配置时的插件筛选。 Whitelist 非空时只保留名单内的 kind;Blacklist 始终排除对应 kind。
type TypedInstance ¶
TypedInstance 是已构造实例及其图 id 和 kind。
func CollectInstances ¶
func CollectInstances[T any](result *Result) []TypedInstance[T]
CollectInstances 返回所有匹配实例及其 id 和 kind。 result 为 nil 时返回 nil。