Documentation
¶
Index ¶
- Variables
- func Get[T any](ctx *InitContext, key typedmap.TypedKey[T]) (T, bool)
- func GetOrDefault[T any](ctx *InitContext, key typedmap.TypedKey[T], defaultValue T) T
- func MustGet[T any](ctx *InitContext, key typedmap.TypedKey[T]) T
- func RegisterConnectServiceHandler(router gin.IRouter, basePathWithoutTrailingSlash string, servicePath string, ...)
- func RegisterInitializer(initializer *Initializer)
- func ResetInitializersForTest()
- func Set[T any](ctx *InitContext, key typedmap.TypedKey[T], val T)
- type Engine
- type InitContext
- type Initializer
- type InitializerID
Constants ¶
This section is empty.
Variables ¶
var ( // ResolvedInitializersKey stores the topologically resolved Initializers. ResolvedInitializersKey = typedmap.NewTypedKey[[]*Initializer]("khi.google.com/init/resolved-initializers") )
Functions ¶
func Get ¶ added in v0.58.2
func Get[T any](ctx *InitContext, key typedmap.TypedKey[T]) (T, bool)
Get retrieves a typed value from InitContext.
func GetOrDefault ¶ added in v0.58.2
func GetOrDefault[T any](ctx *InitContext, key typedmap.TypedKey[T], defaultValue T) T
GetOrDefault retrieves a typed value or returns defaultValue if not found.
func MustGet ¶ added in v0.58.2
func MustGet[T any](ctx *InitContext, key typedmap.TypedKey[T]) T
MustGet retrieves a typed value or panics if not found.
func RegisterConnectServiceHandler ¶ added in v0.58.2
func RegisterConnectServiceHandler(router gin.IRouter, basePathWithoutTrailingSlash string, servicePath string, handler http.Handler)
RegisterConnectServiceHandler registers a Connect-RPC service handler to the Gin router, wrapping it to strip the basePath if needed.
func RegisterInitializer ¶ added in v0.58.2
func RegisterInitializer(initializer *Initializer)
RegisterInitializer registers an Initializer into the global registry.
func ResetInitializersForTest ¶ added in v0.58.2
func ResetInitializersForTest()
ResetInitializersForTest clears registered initializers for unit testing.
Types ¶
type Engine ¶ added in v0.58.2
type Engine struct {
// contains filtered or unexported fields
}
Engine manages the initialization, execution, and termination lifecycle of KHI.
func NewEngine ¶ added in v0.58.2
NewEngine creates a new Engine wrapping the provided parent context.
func (*Engine) Context ¶ added in v0.58.2
func (e *Engine) Context() *InitContext
Context returns the InitContext managed by this engine.
func (*Engine) Init ¶ added in v0.58.2
Init resolves and executes all registered Initializers in topological order.
type InitContext ¶ added in v0.58.2
InitContext is passed to Initializers to share state and register lifecycle hooks.
func (*InitContext) OnRun ¶ added in v0.58.2
func (c *InitContext) OnRun(hook func(ctx context.Context) error)
OnRun registers a runtime hook with the Engine.
func (*InitContext) OnTerminate ¶ added in v0.58.2
func (c *InitContext) OnTerminate(hook func() error)
OnTerminate registers a shutdown hook with the Engine.
type Initializer ¶ added in v0.58.2
type Initializer struct {
// ID is the unique identifier of this initializer.
ID InitializerID
// Dependencies lists the InitializerIDs that must execute before this initializer.
Dependencies []InitializerID
// Before lists the InitializerIDs that this initializer must execute before.
Before []InitializerID
// Init executes the initialization logic.
Init func(ctx *InitContext) error
}
Initializer represents an initialization unit in the DAG.
type InitializerID ¶ added in v0.58.2
type InitializerID string
InitializerID identifies an Initializer uniquely.