manager

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Close

func (*BaseComponent) Close(ctx context.Context) error

func (*BaseComponent) Init

func (*BaseComponent) Init() error

func (*BaseComponent) Options

func (*BaseComponent) Options() Options

func (*BaseComponent) Start

func (*BaseComponent) Start(ctx context.Context) error

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 New

func New() *Manager

func (*Manager) Build

func (manager *Manager) Build() error

Build constructs all components.

func (*Manager) Close

func (manager *Manager) Close(ctx context.Context, logger logrus.FieldLogger) error

func (*Manager) Dot

func (manager *Manager) Dot() string

func (*Manager) Init

func (manager *Manager) Init(ctx context.Context, logger logrus.FieldLogger) error

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

func (manager *Manager) ProvideUtil(factory any)

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 *Manager) SetupFlags(fs *pflag.FlagSet)

func (*Manager) Start

func (manager *Manager) Start(logger logrus.FieldLogger, ctx context.Context) error

func (*Manager) TrimDisabled

func (manager *Manager) TrimDisabled(logger logrus.FieldLogger)

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

func NewMockMux

func NewMockMux(name string, which string, whichValue MuxImpl) *Mux

func NewMux

func NewMux(name string, explicitEnable bool) *Mux

func (*Mux) Close

func (mux *Mux) Close(ctx context.Context) error

func (*Mux) EnableFlag

func (mux *Mux) EnableFlag() *bool

func (*Mux) Impl

func (mux *Mux) Impl() MuxImpl

func (*Mux) Init

func (mux *Mux) Init() error

func (*Mux) IsMux

func (mux *Mux) IsMux() *Mux

func (*Mux) Options

func (mux *Mux) Options() Options

func (*Mux) Setup

func (mux *Mux) Setup(fs *pflag.FlagSet)

func (*Mux) Start

func (mux *Mux) Start(ctx context.Context) error

func (*Mux) WithAdditionalOptions

func (mux *Mux) WithAdditionalOptions(options MuxAdditionalOptions) *Mux

func (*Mux) WithImpl

func (mux *Mux) WithImpl(impl MuxImpl) *Mux

type MuxAdditionalOptions

type MuxAdditionalOptions interface {
	Setup(fs *pflag.FlagSet)
}

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 NoOptions

type NoOptions struct{}

func (*NoOptions) EnableFlag

func (*NoOptions) EnableFlag() *bool

func (*NoOptions) Setup

func (*NoOptions) Setup(fs *pflag.FlagSet)

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.

type UtilContext

type UtilContext struct {
	ComponentName string
	ComponentType reflect.Type

	// Adds a closure that is called before calling Init() on the referencing component
	AddOnInit func(func() error)
}

Jump to

Keyboard shortcuts

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