Documentation ¶
Index ¶
- Constants
- func CheckError(err error)
- func ContainsString(s []string, e string) bool
- type ActuatorController
- type Context
- func (c *Context) GetController(name string) IController
- func (c *Context) GetControllers() []IController
- func (c *Context) GetService(name string) IService
- func (c *Context) GetServices() []IService
- func (c *Context) GetUIController() IUIController
- func (c *Context) RegisterController(controller IController)
- func (c *Context) RegisterService(service IService)
- func (c *Context) RegisterUIController(uiController IUIController)
- type ControllerFactory
- type IContext
- type IController
- type IRunner
- type IService
- type IUIController
- type MockController
- type MockService
- type Runner
- type ServiceFactory
- type UIControllerFactory
Constants ¶
const ActuatorControllerName = "actuator"
ActuatorControllerName is the name of the actuator controller for DI
Variables ¶
This section is empty.
Functions ¶
func CheckError ¶
func CheckError(err error)
CheckError checks for an error and exits the process with result code 1 if err is set
func ContainsString ¶
ContainsString checks if a slice of strings contains a string
Types ¶
type ActuatorController ¶
type ActuatorController struct {
// contains filtered or unexported fields
}
ActuatorController is a controller running in a separate thread providing an health endpoint
func (*ActuatorController) Health ¶
func (c *ActuatorController) Health() error
Health checks if the http server properly started
func (*ActuatorController) Name ¶
func (c *ActuatorController) Name() string
Name returns the name of the actuator controller from ActuatorControllerName
func (*ActuatorController) Start ¶
func (c *ActuatorController) Start() error
Start starts a HTTP-server for health-checks
func (*ActuatorController) Stop ¶
func (c *ActuatorController) Stop() error
Stop currently does nothing
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is used for dependency injection (DI) from Runner to services and controllers
func NewContext ¶
func NewContext() *Context
NewContext creates a new initialized instance of Context
func (*Context) GetController ¶
func (c *Context) GetController(name string) IController
GetController returns a controller by its name
Causes a fatal failure if no controller is registered for this name
func (*Context) GetControllers ¶
func (c *Context) GetControllers() []IController
GetControllers returns a list of all registered controllers
func (*Context) GetService ¶
GetService returns a service by its name
Causes a fatal failure if no service is registered for this name
func (*Context) GetServices ¶
GetServices returns a list of all registered services
func (*Context) GetUIController ¶
func (c *Context) GetUIController() IUIController
GetUIController returns the registered UI-Controller or nil
func (*Context) RegisterController ¶
func (c *Context) RegisterController(controller IController)
RegisterController registers a controller by its name (returned by IController.Name())
Causes a fatal failure if the name is empty or already in use
func (*Context) RegisterService ¶
RegisterService registers a service by its name (returned by IService.Name())
Causes a fatal failure if the name is empty or already in use
func (*Context) RegisterUIController ¶
func (c *Context) RegisterUIController(uiController IUIController)
RegisterUIController registers a UI-Controller
Causes a fatal failure if an UI-Controller was already registered
type ControllerFactory ¶
type ControllerFactory func(ctx IContext) IController
ControllerFactory defines the factory function for creating new instances of the controller
type IContext ¶
type IContext interface { RegisterService(service IService) RegisterController(controller IController) RegisterUIController(uiController IUIController) GetService(name string) IService GetServices() []IService GetController(name string) IController GetControllers() []IController GetUIController() IUIController }
IContext defines the interface of Context used for dependency injection (DI)
type IController ¶
IController is the base type for all controllers
func NewActuatorController ¶
func NewActuatorController(ctx IContext) IController
NewActuatorController creates a new initilized instance of ActuatorController
type IRunner ¶
type IRunner interface { CreateService(serviceFactory ServiceFactory) CreateController(controllerFactory ControllerFactory) CreateUIController(uiControllerFactory UIControllerFactory) AwaitReady() Run() Kill() }
IRunner defines the interface of the core Runner
type IUIController ¶
type IUIController interface { IController Run(chan os.Signal) error }
IUIController is a special controller that can be used for an ui and is executed on the main thread
type MockController ¶
type MockController struct { NameFunc func() string StartFunc func() error StopFunc func() error HealthFunc func() error NameFuncCalled int StartFuncCalled int StopFuncCalled int HealthFuncCalled int }
MockController for simply mocking IController
func NewMockController ¶
func NewMockController() *MockController
NewMockController creates a new initialized instance of MockController
func (*MockController) Health ¶
func (c *MockController) Health() error
Health calls HealthFunc and increases HealthFuncCalled
func (*MockController) Name ¶
func (c *MockController) Name() string
Name calls NameFunc and increases NameFuncCalled
func (*MockController) Start ¶
func (c *MockController) Start() error
Start calls StartFunc and increases StartFuncCalled
func (*MockController) Stop ¶
func (c *MockController) Stop() error
Stop calls StopFunc and increases StopFuncCalled
type MockService ¶
type MockService struct { NameFunc func() string StartFunc func() error StopFunc func() error HealthFunc func() error NameFuncCalled int StartFuncCalled int StopFuncCalled int HealthFuncCalled int }
MockService for simply mocking IService
func NewMockService ¶
func NewMockService() *MockService
NewMockService creates a new initialized instance of MockService
func (*MockService) Health ¶
func (c *MockService) Health() error
Health calls HealthFunc and increases HealthFuncCalled
func (*MockService) Name ¶
func (c *MockService) Name() string
Name calls NameFunc and increases NameFuncCalled
func (*MockService) Start ¶
func (c *MockService) Start() error
Start calls StartFunc and increases StartFuncCalled
func (*MockService) Stop ¶
func (c *MockService) Stop() error
Stop calls StopFunc and increases StopFuncCalled
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner is the core struct responsible for dependency injection and starting / stopping services & controllers
func (*Runner) AwaitReady ¶
func (r *Runner) AwaitReady()
AwaitReady is a blocking function waiting for the Runner to have started all services and controllers
func (*Runner) CreateController ¶
func (r *Runner) CreateController(controllerFactory ControllerFactory)
CreateController creates a new instance of a controller using its factory function and registers it in the context
func (*Runner) CreateService ¶
func (r *Runner) CreateService(serviceFactory ServiceFactory)
CreateService creates a new instance of a service using its factory function and registers it in the context
func (*Runner) CreateUIController ¶
func (r *Runner) CreateUIController(uiControllerFactory UIControllerFactory)
CreateUIController creates a new instance of an UI-Controller using its factory function and registers it in the context
type ServiceFactory ¶
ServiceFactory defines the factory function for creating new instances of the service
type UIControllerFactory ¶
type UIControllerFactory func(ctx IContext) IUIController
UIControllerFactory defines the factory function for creating new instances of the ui controller