gousu

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 8 Imported by: 22

Documentation

Index

Constants

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

func ContainsString(s []string, e string) bool

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

func (c *Context) GetService(name string) IService

GetService returns a service by its name

Causes a fatal failure if no service is registered for this name

func (*Context) GetServices

func (c *Context) GetServices() []IService

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

func (c *Context) RegisterService(service IService)

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

type IController interface {
	Name() string

	Start() error
	Stop() error
	Health() error
}

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

func NewRunner

func NewRunner(projectName string, version string) IRunner

NewRunner creates a new initialized instance of Runner, also initializing the config flags and the logger

type IService

type IService interface {
	Name() string

	Start() error
	Stop() error
	Health() error
}

IService is the base type for all services

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

func (*Runner) Kill

func (r *Runner) Kill()

Kill sends a SIGINt signal to the Runner causing it to stop

func (*Runner) Run

func (r *Runner) Run()

Run is the blocking core function starting all services & controllers, waiting for a SIGINT or SIGTERM signal an the stopping all

type ServiceFactory

type ServiceFactory func(ctx IContext) IService

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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