Documentation
¶
Overview ¶
Package kernel provides the dependency injection container and module bootstrapping logic.
Index ¶
- Variables
- func ExportAppGraph(app *App, format GraphFormat) (string, error)
- func ExportGraph(g *Graph, format GraphFormat) (string, error)
- type App
- type BootstrapOption
- type BootstrapOptionConflictError
- type Container
- type ControllerBuildError
- type DuplicateControllerNameError
- type DuplicateModuleNameError
- type DuplicateOverrideTokenError
- type DuplicateProviderTokenError
- type ExportAmbiguousError
- type ExportNotVisibleError
- type Graph
- type GraphFormat
- type GraphNodeNotFoundError
- type InvalidModuleDefError
- type InvalidModuleNameError
- type ModuleCycleError
- type ModuleNode
- type ModuleNotPointerError
- type NilBootstrapOptionError
- type NilImportError
- type OverrideBuildNilError
- type OverrideTokenNotFoundError
- type OverrideTokenNotVisibleFromRootError
- type ProviderBuildError
- type ProviderCycleError
- type ProviderNotFoundError
- type ProviderOverride
- type RootModuleNilError
- type TokenNotVisibleError
- type UnsupportedGraphFormatError
- type Visibility
Constants ¶
This section is empty.
Variables ¶
var ErrExportAmbiguous = errors.New("export token is ambiguous across imports")
ErrExportAmbiguous is returned when a module tries to re-export a token that multiple imports provide.
var ErrGraphNodeNotFound = errors.New("graph node not found")
ErrGraphNodeNotFound is returned when graph export references a missing node.
var ErrNilApp = errors.New("app is nil")
ErrNilApp is returned when an operation requiring an app receives nil.
var ErrNilGraph = errors.New("graph is nil")
ErrNilGraph is returned when BuildVisibility is called with a nil graph.
Functions ¶
func ExportAppGraph ¶ added in v0.14.0
func ExportAppGraph(app *App, format GraphFormat) (string, error)
ExportAppGraph exports the app's module graph in the requested format.
func ExportGraph ¶ added in v0.14.0
func ExportGraph(g *Graph, format GraphFormat) (string, error)
ExportGraph exports a graph in Mermaid or DOT format.
Types ¶
type App ¶
type App struct {
Graph *Graph
Controllers map[string]any
// contains filtered or unexported fields
}
App represents a bootstrapped modkit application with its dependency graph, container, and instantiated controllers.
func Bootstrap ¶
Bootstrap constructs a modkit application from a root module. It builds the module graph, validates dependencies, creates the DI container, and instantiates all controllers.
func BootstrapWithOptions ¶ added in v0.13.0
func BootstrapWithOptions(root module.Module, opts ...BootstrapOption) (*App, error)
BootstrapWithOptions constructs a modkit application from a root module and explicit bootstrap options.
func (*App) CleanupHooks ¶ added in v0.4.0
CleanupHooks returns provider cleanup hooks in LIFO order.
func (*App) Close ¶ added in v0.5.0
Close closes providers implementing io.Closer in reverse build order.
func (*App) CloseContext ¶ added in v0.7.0
CloseContext closes providers implementing io.Closer in reverse build order.
type BootstrapOption ¶ added in v0.13.0
type BootstrapOption interface {
// contains filtered or unexported methods
}
BootstrapOption configures advanced bootstrap behavior.
func WithProviderOverrides ¶ added in v0.13.0
func WithProviderOverrides(overrides ...ProviderOverride) BootstrapOption
WithProviderOverrides applies token-level provider overrides for bootstrap.
type BootstrapOptionConflictError ¶ added in v0.13.0
BootstrapOptionConflictError is returned when multiple options mutate the same token.
func (*BootstrapOptionConflictError) Error ¶ added in v0.13.0
func (e *BootstrapOptionConflictError) Error() string
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is the dependency injection container that manages provider instances, enforces visibility rules, and tracks cleanup hooks.
type ControllerBuildError ¶
ControllerBuildError wraps an error that occurred while building a controller instance.
func (*ControllerBuildError) Error ¶
func (e *ControllerBuildError) Error() string
func (*ControllerBuildError) Unwrap ¶
func (e *ControllerBuildError) Unwrap() error
type DuplicateControllerNameError ¶
DuplicateControllerNameError is returned when a module has multiple controllers with the same name.
func (*DuplicateControllerNameError) Error ¶
func (e *DuplicateControllerNameError) Error() string
type DuplicateModuleNameError ¶
type DuplicateModuleNameError struct {
Name string
}
DuplicateModuleNameError is returned when multiple modules have the same name.
func (*DuplicateModuleNameError) Error ¶
func (e *DuplicateModuleNameError) Error() string
type DuplicateOverrideTokenError ¶ added in v0.13.0
DuplicateOverrideTokenError is returned when the same override token is declared more than once.
func (*DuplicateOverrideTokenError) Error ¶ added in v0.13.0
func (e *DuplicateOverrideTokenError) Error() string
type DuplicateProviderTokenError ¶
DuplicateProviderTokenError is returned when the same provider token is registered in multiple modules.
func (*DuplicateProviderTokenError) Error ¶
func (e *DuplicateProviderTokenError) Error() string
type ExportAmbiguousError ¶ added in v0.6.0
ExportAmbiguousError is returned when a module re-exports a token that multiple imports provide.
func (*ExportAmbiguousError) Error ¶ added in v0.6.0
func (e *ExportAmbiguousError) Error() string
func (*ExportAmbiguousError) Unwrap ¶ added in v0.6.0
func (e *ExportAmbiguousError) Unwrap() error
type ExportNotVisibleError ¶
ExportNotVisibleError is returned when a module exports a token it cannot access.
func (*ExportNotVisibleError) Error ¶
func (e *ExportNotVisibleError) Error() string
type Graph ¶
type Graph struct {
Root string
Modules []ModuleNode
Nodes map[string]*ModuleNode
}
Graph represents the complete module dependency graph with all nodes and import relationships.
type GraphFormat ¶ added in v0.14.0
type GraphFormat string
GraphFormat selects the serialization format for graph export.
const ( // GraphFormatMermaid exports the graph as Mermaid flowchart text. GraphFormatMermaid GraphFormat = "mermaid" // GraphFormatDOT exports the graph as Graphviz DOT text. GraphFormatDOT GraphFormat = "dot" )
type GraphNodeNotFoundError ¶ added in v0.14.0
type GraphNodeNotFoundError struct {
Node string
}
GraphNodeNotFoundError is returned when graph export cannot find a node by name.
func (*GraphNodeNotFoundError) Error ¶ added in v0.14.0
func (e *GraphNodeNotFoundError) Error() string
func (*GraphNodeNotFoundError) Unwrap ¶ added in v0.14.0
func (e *GraphNodeNotFoundError) Unwrap() error
type InvalidModuleDefError ¶
InvalidModuleDefError is returned when a module's Definition() returns invalid metadata.
func (*InvalidModuleDefError) Error ¶
func (e *InvalidModuleDefError) Error() string
func (*InvalidModuleDefError) Unwrap ¶
func (e *InvalidModuleDefError) Unwrap() error
type InvalidModuleNameError ¶
type InvalidModuleNameError struct {
Name string
}
InvalidModuleNameError is returned when a module has an empty or invalid name.
func (*InvalidModuleNameError) Error ¶
func (e *InvalidModuleNameError) Error() string
type ModuleCycleError ¶
type ModuleCycleError struct {
Path []string
}
ModuleCycleError is returned when a circular dependency exists in module imports.
func (*ModuleCycleError) Error ¶
func (e *ModuleCycleError) Error() string
type ModuleNode ¶
ModuleNode represents a module in the dependency graph with its definition and import names.
type ModuleNotPointerError ¶
type ModuleNotPointerError struct {
Module string
}
ModuleNotPointerError is returned when a module is not passed by pointer.
func (*ModuleNotPointerError) Error ¶
func (e *ModuleNotPointerError) Error() string
type NilBootstrapOptionError ¶ added in v0.13.0
type NilBootstrapOptionError struct {
Index int
}
NilBootstrapOptionError is returned when a nil bootstrap option is passed.
func (*NilBootstrapOptionError) Error ¶ added in v0.13.0
func (e *NilBootstrapOptionError) Error() string
type NilImportError ¶
NilImportError is returned when a module has a nil entry in its Imports slice.
func (*NilImportError) Error ¶
func (e *NilImportError) Error() string
type OverrideBuildNilError ¶ added in v0.13.0
OverrideBuildNilError is returned when an override has a nil Build function.
func (*OverrideBuildNilError) Error ¶ added in v0.13.0
func (e *OverrideBuildNilError) Error() string
type OverrideTokenNotFoundError ¶ added in v0.13.0
OverrideTokenNotFoundError is returned when an override token does not exist in the provider graph.
func (*OverrideTokenNotFoundError) Error ¶ added in v0.13.0
func (e *OverrideTokenNotFoundError) Error() string
type OverrideTokenNotVisibleFromRootError ¶ added in v0.13.0
OverrideTokenNotVisibleFromRootError is returned when an override token is not visible from root scope.
func (*OverrideTokenNotVisibleFromRootError) Error ¶ added in v0.13.0
func (e *OverrideTokenNotVisibleFromRootError) Error() string
type ProviderBuildError ¶
ProviderBuildError wraps an error that occurred while building a provider instance.
func (*ProviderBuildError) Error ¶
func (e *ProviderBuildError) Error() string
func (*ProviderBuildError) Unwrap ¶
func (e *ProviderBuildError) Unwrap() error
type ProviderCycleError ¶
ProviderCycleError is returned when a circular dependency exists in provider resolution.
func (*ProviderCycleError) Error ¶
func (e *ProviderCycleError) Error() string
type ProviderNotFoundError ¶
ProviderNotFoundError is returned when attempting to resolve a token that has no registered provider.
func (*ProviderNotFoundError) Error ¶
func (e *ProviderNotFoundError) Error() string
type ProviderOverride ¶ added in v0.13.0
type ProviderOverride struct {
Token module.Token
Build func(module.Resolver) (any, error)
Cleanup func(context.Context) error
}
ProviderOverride replaces provider build/cleanup behavior for a token at bootstrap time.
type RootModuleNilError ¶
type RootModuleNilError struct{}
RootModuleNilError is returned when Bootstrap is called with a nil root module.
func (*RootModuleNilError) Error ¶
func (e *RootModuleNilError) Error() string
type TokenNotVisibleError ¶
TokenNotVisibleError is returned when a module attempts to resolve a token that isn't visible to it.
func (*TokenNotVisibleError) Error ¶
func (e *TokenNotVisibleError) Error() string
type UnsupportedGraphFormatError ¶ added in v0.14.0
type UnsupportedGraphFormatError struct {
Format GraphFormat
}
UnsupportedGraphFormatError is returned when graph export receives an unsupported format.
func (*UnsupportedGraphFormatError) Error ¶ added in v0.14.0
func (e *UnsupportedGraphFormatError) Error() string
type Visibility ¶
Visibility represents which provider tokens are accessible from each module. The outer map key is the module name, the inner map contains visible tokens.
func BuildVisibility ¶ added in v0.6.0
func BuildVisibility(graph *Graph) (Visibility, error)
BuildVisibility constructs the visibility map for all modules in the graph, ensuring exports are valid and detecting ambiguous re-exports.