Documentation ¶
Index ¶
- Variables
- func ExecCollectValues[T directive.Value](ctx context.Context, bus Bus, dir directive.Directive, waitOne bool, ...) ([]T, directive.Instance, directive.Reference, error)
- func ExecOneOff(ctx context.Context, bus Bus, dir directive.Directive, idleCb ExecIdleCallback, ...) (directive.AttachedValue, directive.Instance, directive.Reference, error)
- func ExecOneOffWatchCb[T directive.ComparableValue](cb func(val directive.TypedAttachedValue[T]) bool, b Bus, ...) (directive.Instance, directive.Reference, error)
- func ExecOneOffWatchCh[T directive.ComparableValue](b Bus, dir directive.Directive) (<-chan directive.TypedAttachedValue[T], directive.Instance, ...)
- func ExecOneOffWatchCtr[T directive.ComparableValue](ctr *ccontainer.CContainer[T], b Bus, dir directive.Directive) (directive.Instance, directive.Reference, error)
- func ExecOneOffWatchRoutine[T directive.ComparableValue](routineCtr *routine.StateRoutineContainer[T], b Bus, dir directive.Directive) (directive.Instance, directive.Reference, error)
- func ExecOneOffWithFilter(ctx context.Context, bus Bus, dir directive.Directive, idleCb ExecIdleCallback, ...) (directive.AttachedValue, directive.Instance, directive.Reference, error)
- func ExecWaitValue[T directive.Value](ctx context.Context, b Bus, dir directive.Directive, ...) (T, directive.Instance, directive.Reference, error)
- func NewCallbackHandler(valCb func(directive.AttachedValue), removedCb func(directive.AttachedValue), ...) directive.ReferenceHandler
- func NewPassThruHandler(passthru directive.ResolverHandler, disposeCb func()) directive.ReferenceHandler
- func NewTransformHandler(passthru directive.ResolverHandler, ...) directive.ReferenceHandler
- type Bus
- type BusController
- func (c *BusController[T]) Close() error
- func (c *BusController[T]) Execute(ctx context.Context) error
- func (c *BusController[T]) GetBus() Bus
- func (c *BusController[T]) GetConfig() T
- func (c *BusController[T]) GetControllerInfo() *controller.Info
- func (c *BusController[T]) GetLogger() *logrus.Entry
- func (c *BusController[T]) HandleDirective(ctx context.Context, di directive.Instance) ([]directive.Resolver, error)
- type BusFactory
- func NewBusControllerFactory[T config.Config, C controller.Controller](b Bus, configID string, controllerID string, version semver.Version, ...) *BusFactory[T, C]
- func NewBusFactory[T config.Config, C controller.Controller](b Bus, configID string, version semver.Version, newConfig func() T, ...) *BusFactory[T, C]
- type CallbackHandler
- type ExecIdleCallback
- type PassThruHandler
- type TransformHandler
Constants ¶
This section is empty.
Variables ¶
var ErrDirectiveDisposed = errors.New("directive disposed unexpectedly")
ErrDirectiveDisposed is returned when the directive was unexpectedly disposed.
Functions ¶
func ExecCollectValues ¶
func ExecCollectValues[T directive.Value]( ctx context.Context, bus Bus, dir directive.Directive, waitOne bool, valDisposeCb func(), ) ([]T, directive.Instance, directive.Reference, error)
ExecCollectValues collects one or more values while ctx is active and directive is not idle.
Returns vals, ref, nil if the directive is idle. Returns err if any resolver returns an error. valDisposeCb is called if any of the values are no longer valid. valDisposeCb might be called multiple times. If err != nil, ref == nil. If waitOne=true, waits for at least one value before returning.
func ExecOneOff ¶
func ExecOneOff( ctx context.Context, bus Bus, dir directive.Directive, idleCb ExecIdleCallback, valDisposeCallback func(), ) (directive.AttachedValue, directive.Instance, directive.Reference, error)
ExecOneOff executes a one-off directive.
idleCb is called when idle with the list of resolver errors. idleCb should return (wait, error): if wait=true, continues to wait. if idleCb is nil: continues to wait when the directive becomes idle errs is the list of errors from the resolvers (if any)
If any resolvers return an error, returns that error. valDisposeCb is called if the value is no longer valid. valDisposeCb might be called multiple times. If err != nil, ref == nil.
func ExecOneOffWatchCb ¶ added in v0.34.0
func ExecOneOffWatchCb[T directive.ComparableValue]( cb func(val directive.TypedAttachedValue[T]) bool, b Bus, dir directive.Directive, ) (directive.Instance, directive.Reference, error)
ExecOneOffWatchCb executes a one-off directive and watches for changes. Selects one value from the result. Calls the callback when the selected value changes. Calls with nil when the value becomes unset. If the callback returns false, the value is rejected, and the next value will be used instead.
func ExecOneOffWatchCh ¶ added in v0.8.7
func ExecOneOffWatchCh[T directive.ComparableValue]( b Bus, dir directive.Directive, ) (<-chan directive.TypedAttachedValue[T], directive.Instance, directive.Reference, error)
ExecOneOffWatchCh executes a one-off directive and watches for changes. Returns a channel with size 1 which will hold the latest value. Continues to watch for changes until the directive is released.
func ExecOneOffWatchCtr ¶ added in v0.28.0
func ExecOneOffWatchCtr[T directive.ComparableValue]( ctr *ccontainer.CContainer[T], b Bus, dir directive.Directive, ) ( directive.Instance, directive.Reference, error, )
ExecOneOffWatchCtr executes a one-off directive and watches for changes. Stores the latest value into the ccontainer. Continues to watch for changes until the directive is released.
func ExecOneOffWatchRoutine ¶ added in v0.22.4
func ExecOneOffWatchRoutine[T directive.ComparableValue]( routineCtr *routine.StateRoutineContainer[T], b Bus, dir directive.Directive, ) (directive.Instance, directive.Reference, error)
ExecOneOffWatchRoutine executes a one-off directive and watches for changes.
Calls SetState on the routine container. The routine will be restarted when the value changes. Note: the routine will not start until SetContext and SetStateRoutine are called on the routine container.
func ExecOneOffWithFilter ¶ added in v0.20.8
func ExecOneOffWithFilter( ctx context.Context, bus Bus, dir directive.Directive, idleCb ExecIdleCallback, valDisposeCallback func(), filterCb func(val directive.AttachedValue) (bool, error), ) (directive.AttachedValue, directive.Instance, directive.Reference, error)
ExecOneOffWithFilter executes a one-off directive with a filter cb.
Waits until the callback returns true before returning a value. valDisposeCb is called if the value is no longer valid. valDisposeCb might be called multiple times.
idleCb is called when idle with the list of resolver errors. idleCb should return (wait, error): if wait=true, continues to wait. if idleCb is nil: continues to wait when the directive becomes idle errs is the list of errors from the resolvers (if any)
If err != nil, ref == nil.
func ExecWaitValue ¶ added in v0.15.0
func ExecWaitValue[T directive.Value]( ctx context.Context, b Bus, dir directive.Directive, idleCb func(errs []error) (bool, error), valDisposeCallback func(), checkCb func(val T) (bool, error), ) (T, directive.Instance, directive.Reference, error)
ExecWaitValue executes a directive and waits for a value matching the cb.
valDisposeCallback can be nil, will be called if the value is disposed. If cb returns true, nil, returns the value. If checkCb is nil, returns first value.
idleCb is called when idle with the list of resolver errors. idleCb should return (wait, error): if wait=true, continues to wait. if idleCb is nil: continues to wait when the directive becomes idle errs is the list of errors from the resolvers (if any)
func NewCallbackHandler ¶
func NewCallbackHandler( valCb func(directive.AttachedValue), removedCb func(directive.AttachedValue), disposeCb func(), ) directive.ReferenceHandler
NewCallbackHandler wraps callback functions into a handler object.
func NewPassThruHandler ¶
func NewPassThruHandler( passthru directive.ResolverHandler, disposeCb func(), ) directive.ReferenceHandler
NewPassThruHandler builds a new pass-through handler.
func NewTransformHandler ¶ added in v0.29.2
func NewTransformHandler( passthru directive.ResolverHandler, xfrm func(val directive.AttachedValue) (directive.Value, bool), disposeCb func(), ) directive.ReferenceHandler
NewTransformHandler builds a new pass-through handler.
Types ¶
type Bus ¶
type Bus interface { // Controller is the directive controller. directive.Controller // GetControllers returns a list of all currently active controllers. GetControllers() []controller.Controller // AddController adds a controller to the bus and calls Execute(). // The controller will exit if ctx is canceled. // Returns a release function for the controller reference. // The controller will receive directive callbacks until removed. // Any fatal error in the controller is written to cb. // If the controller is released, cb will be called with nil. // cb can be nil AddController(ctx context.Context, ctrl controller.Controller, cb func(exitErr error)) (func(), error) // ExecuteController adds a controller to the bus and calls Execute(). // The controller will exit if ctx is canceled. // Any fatal error in the controller is returned. // The controller will receive directive callbacks. // If this function returns nil, call RemoveController to remove the controller. ExecuteController(context.Context, controller.Controller) error // RemoveController removes the controller from the bus. // The controller will no longer receive callbacks. // Note: this might not cancel the Execute() context automatically. RemoveController(controller.Controller) }
Bus manages running controllers. It has an attached directive controller, which is used to build declarative state requests between controllers.
type BusController ¶ added in v0.15.1
BusController implements a base Controller with an attached Bus for directives. It has stubs for the functions implementing all required interfaces. Usually you should extend this type, overriding functions as needed.
func NewBusController ¶ added in v0.15.1
func NewBusController[T config.Config]( le *logrus.Entry, b Bus, conf T, controllerID string, controllerVersion semver.Version, controllerDescrip string, ) *BusController[T]
NewBusController constructs a new Controller with details.
func (*BusController[T]) Close ¶ added in v0.15.1
func (c *BusController[T]) Close() error
Close releases any resources used by the controller.
func (*BusController[T]) Execute ¶ added in v0.15.1
func (c *BusController[T]) Execute(ctx context.Context) error
Execute executes the given controller.
func (*BusController[T]) GetBus ¶ added in v0.15.1
func (c *BusController[T]) GetBus() Bus
GetBus returns the bus.
func (*BusController[T]) GetConfig ¶ added in v0.15.1
func (c *BusController[T]) GetConfig() T
GetConfig returns the config. Note: don't modify this object!
func (*BusController[T]) GetControllerInfo ¶ added in v0.15.1
func (c *BusController[T]) GetControllerInfo() *controller.Info
GetControllerInfo returns information about the controller.
func (*BusController[T]) GetLogger ¶ added in v0.15.1
func (c *BusController[T]) GetLogger() *logrus.Entry
GetLogger returns the root logger.
func (*BusController[T]) HandleDirective ¶ added in v0.15.1
func (c *BusController[T]) HandleDirective(ctx context.Context, di directive.Instance) ([]directive.Resolver, error)
HandleDirective asks if the handler can resolve the directive.
type BusFactory ¶ added in v0.15.0
type BusFactory[T config.Config, C controller.Controller] struct { // contains filtered or unexported fields }
BusFactory implements Factory with an attached Bus for directives.
func NewBusControllerFactory ¶ added in v0.15.1
func NewBusControllerFactory[T config.Config, C controller.Controller]( b Bus, configID string, controllerID string, version semver.Version, controllerDescription string, newConfig func() T, newController func(base *BusController[T]) (C, error), ) *BusFactory[T, C]
NewBusControllerFactory builds a Factory for a type wrapping BusController.
func NewBusFactory ¶ added in v0.23.2
func NewBusFactory[T config.Config, C controller.Controller]( b Bus, configID string, version semver.Version, newConfig func() T, newController func(le *logrus.Entry, b Bus, conf T) (C, error), ) *BusFactory[T, C]
NewBusFactory constructs a new Factory with details.
func (*BusFactory[T, C]) Construct ¶ added in v0.15.0
func (f *BusFactory[T, C]) Construct(cc config.Config, opts controller.ConstructOpts) (controller.Controller, error)
Construct constructs the associated controller given configuration.
func (*BusFactory[T, C]) ConstructConfig ¶ added in v0.15.0
func (f *BusFactory[T, C]) ConstructConfig() config.Config
ConstructConfig constructs an instance of the controller configuration.
func (*BusFactory[T, C]) GetConfigID ¶ added in v0.15.0
func (f *BusFactory[T, C]) GetConfigID() string
GetConfigID returns the unique config ID for the controller.
func (*BusFactory[T, C]) GetVersion ¶ added in v0.15.0
func (f *BusFactory[T, C]) GetVersion() semver.Version
GetVersion returns the version of this controller.
type CallbackHandler ¶
type CallbackHandler = directive.CallbackHandler
CallbackHandler is a reference handler that uses function callbacks.
type ExecIdleCallback ¶ added in v0.27.0
ExecIdleCallback is an idle callback for ExecOneOffWithFilter.
idleCb is called when idle with the list of resolver errors. idleCb should return (wait, error): if wait=true, continues to wait. if idleCb is nil: continues to wait when the directive becomes idle errs is the list of errors from the resolvers (if any)
func ReturnIfIdle ¶ added in v0.27.1
func ReturnIfIdle(returnIfIdle bool) ExecIdleCallback
ReturnIfIdle returns an ExecIdleCallback that returns when the directive becomes idle if true.
func ReturnWhenIdle ¶ added in v0.27.0
func ReturnWhenIdle() ExecIdleCallback
ReturnWhenIdle returns an ExecIdleCallback that returns when the directive becomes idle.
func WaitWhenIdle ¶ added in v0.27.0
func WaitWhenIdle(ignoreErrors bool) ExecIdleCallback
WaitWhenIdle returns an ExecIdleCallback that waits when the directive becomes idle.
if ignoreErrors is false, returns any non-nil resolver error that occurs.
type PassThruHandler ¶
type PassThruHandler struct {
// contains filtered or unexported fields
}
PassThruHandler is a reference handler that passes through to a resolver handler.
func (*PassThruHandler) HandleInstanceDisposed ¶
func (h *PassThruHandler) HandleInstanceDisposed(di directive.Instance)
HandleInstanceDisposed is called when a directive instance is disposed. This will occur if Close() is called on the directive instance.
func (*PassThruHandler) HandleValueAdded ¶
func (h *PassThruHandler) HandleValueAdded( _ directive.Instance, v directive.AttachedValue, )
HandleValueAdded is called when a value is added to the directive.
func (*PassThruHandler) HandleValueRemoved ¶
func (h *PassThruHandler) HandleValueRemoved( _ directive.Instance, v directive.AttachedValue, )
HandleValueRemoved is called when a value is removed from the directive.
type TransformHandler ¶ added in v0.29.2
type TransformHandler struct {
// contains filtered or unexported fields
}
TransformHandler is a reference handler that transforms values to a resolver handler. xfrm is the transformation callback called with each AttachedValue. xfrm should return the Value to add to the ResolverHandler. if xfrm returns nil, false, the value is ignored. if xfrm is nil, acts identically to PassThruHandler.
func (*TransformHandler) HandleInstanceDisposed ¶ added in v0.29.2
func (h *TransformHandler) HandleInstanceDisposed(di directive.Instance)
HandleInstanceDisposed is called when a directive instance is disposed. This will occur if Close() is called on the directive instance.
func (*TransformHandler) HandleValueAdded ¶ added in v0.29.2
func (h *TransformHandler) HandleValueAdded( _ directive.Instance, v directive.AttachedValue, )
HandleValueAdded is called when a value is added to the directive.
func (*TransformHandler) HandleValueRemoved ¶ added in v0.29.2
func (h *TransformHandler) HandleValueRemoved( _ directive.Instance, v directive.AttachedValue, )
HandleValueRemoved is called when a value is removed from the directive.