Documentation ¶
Index ¶
- Variables
- type AlwaysEnableOptions
- type BaseComponent
- type Component
- type ComponentConstruct
- type ComponentFactory
- type GenericUtil
- type IndexedListImpl
- type List
- type ListInterface
- type Manager
- func (manager *Manager) Build() error
- func (manager *Manager) Close(ctx context.Context, logger logrus.FieldLogger) error
- func (manager *Manager) Dot() string
- func (manager *Manager) Init(ctx context.Context, logger logrus.FieldLogger) error
- func (manager *Manager) Provide(name string, factory ComponentFactory)
- func (manager *Manager) ProvideListImpl(name string, factory ComponentFactory, list ListInterface)
- func (manager *Manager) ProvideMuxImpl(name string, factory ComponentFactory, interfaceFunc any)
- func (manager *Manager) ProvideUtil(factory any)
- func (manager *Manager) SetupFlags(fs *pflag.FlagSet)
- func (manager *Manager) Start(logger logrus.FieldLogger, ctx context.Context) error
- func (manager *Manager) TrimDisabled(logger logrus.FieldLogger)
- type Mux
- func (mux *Mux) Close(ctx context.Context) error
- func (mux *Mux) EnableFlag() *bool
- func (mux *Mux) Impl() MuxImpl
- func (mux *Mux) Init() error
- func (mux *Mux) IsMux() *Mux
- func (mux *Mux) Options() Options
- func (mux *Mux) Setup(fs *pflag.FlagSet)
- func (mux *Mux) Start(ctx context.Context) error
- func (mux *Mux) WithAdditionalOptions(options MuxAdditionalOptions) *Mux
- func (mux *Mux) WithImpl(impl MuxImpl) *Mux
- type MuxAdditionalOptions
- type MuxImpl
- type MuxImplBase
- type MuxInterface
- type NoOptions
- type Options
- type UtilContext
Constants ¶
This section is empty.
Variables ¶
var Global = New()
Functions ¶
This section is empty.
Types ¶
type AlwaysEnableOptions ¶
type AlwaysEnableOptions struct{}
func (*AlwaysEnableOptions) EnableFlag ¶
func (*AlwaysEnableOptions) EnableFlag() *bool
func (*AlwaysEnableOptions) Setup ¶
func (*AlwaysEnableOptions) Setup(fs *pflag.FlagSet)
type BaseComponent ¶
type BaseComponent struct{}
func (*BaseComponent) Init ¶
func (*BaseComponent) Init() error
func (*BaseComponent) Options ¶
func (*BaseComponent) Options() Options
type Component ¶
type Component interface { // Returns the options required for this component. Options() Options // Validates options. Initializes the component with a context. Registers inter-component connections. Init() error // Starts the component with a stop channel for shutdown. Start(ctx context.Context) error // Stops the component. This method should not return until all required workers have joined. Close(ctx context.Context) error }
Component is an object that takes in arguments and has a start/stop lifecycle.
type ComponentConstruct ¶
type ComponentConstruct interface {
ComponentConstruct()
}
type ComponentFactory ¶
type ComponentFactory interface { ComponentType() reflect.Type Params() []reflect.Type Call([]reflect.Value) []reflect.Value }
func Func ¶
func Func(closure any) ComponentFactory
func Ptr ¶
func Ptr[CompTy any](obj CompTy) ComponentFactory
type GenericUtil ¶
type GenericUtil interface { ImplementsGenericUtilMarker() // The parameters requested by the util type. UtilReqs() []reflect.Type // Constructs the util type, where the args have types same as the return value of `UtilReqs`. Construct(args []reflect.Value) error }
A generic type that implements GenericUtil can be used as a component parameter.
type IndexedListImpl ¶
type IndexedListImpl interface {
ListIndex() string
}
type List ¶
type List[T any] struct { BaseComponent Impls []T Indexed map[string]T }
type ListInterface ¶
type ListInterface interface {
// contains filtered or unexported methods
}
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) Provide ¶
func (manager *Manager) Provide(name string, factory ComponentFactory)
Provide provides a Component factory that gets called up to once. The factory can accept any number of parameters with types that were provided as roots or components, and return either `T` or `(T, error)`, where `T` is the type of component. The parameter type must be identical to the return type explicitly declared in the factory (not subtypes/supertypes).
func (*Manager) ProvideListImpl ¶
func (manager *Manager) ProvideListImpl(name string, factory ComponentFactory, list ListInterface)
func (*Manager) ProvideMuxImpl ¶
func (manager *Manager) ProvideMuxImpl(name string, factory ComponentFactory, interfaceFunc any)
ProvideMuxImpl provides a MuxImpl factory. It is similar to Manager.Provide(), but with an additional parameter interfaceFunc, where the argument is in the form `Interface.AnyFunc`.
func (*Manager) ProvideUtil ¶
ProvideUtil provides a parameter factory that gets called for every requesting component. The factory should be in the form `func(reflect.Type) (T, error)`, where the input is the type of the requesting component and T is the type of root.
func (*Manager) SetupFlags ¶
func (*Manager) TrimDisabled ¶
func (manager *Manager) TrimDisabled(logger logrus.FieldLogger)
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
func (*Mux) EnableFlag ¶
func (*Mux) WithAdditionalOptions ¶
func (mux *Mux) WithAdditionalOptions(options MuxAdditionalOptions) *Mux
type MuxAdditionalOptions ¶
type MuxImpl ¶
type MuxImpl interface { Component GetMuxImplBase() *MuxImplBase MuxImplName() (name string, isDefault bool) }
type MuxImplBase ¶
type MuxImplBase struct {
// contains filtered or unexported fields
}
func (*MuxImplBase) GetAdditionalOptions ¶
func (base *MuxImplBase) GetAdditionalOptions() MuxAdditionalOptions
func (*MuxImplBase) GetMux ¶
func (base *MuxImplBase) GetMux() Component
func (*MuxImplBase) GetMuxImplBase ¶
func (base *MuxImplBase) GetMuxImplBase() *MuxImplBase
type MuxInterface ¶
type MuxInterface interface {
IsMux() *Mux
}
type Options ¶
type Options interface { // Setup registers required flags into this Options object. Setup(fs *pflag.FlagSet) // EnableFlag returns the option that indicates whether the component should be enabled. // If EnableFlag is non-nil, the component is disabled when *EnableFlag() is false. // Otherwise, the component is disabled when all dependents are disabled. EnableFlag() *bool }
Options is an object that holds the flags.