Documentation
¶
Index ¶
- type Runnable
- type ServiceContainer
- func (c *ServiceContainer) Close()
- func (c *ServiceContainer) GetService(name string) Runnable
- func (c *ServiceContainer) Init()
- func (c *ServiceContainer) RegisterCreator(name string, creator ServiceCreator)
- func (c *ServiceContainer) RegisterService(name string, svc Runnable)
- func (c *ServiceContainer) RunServices()
- type ServiceCreator
- type Stoppable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Runnable ¶
type Runnable interface {
Run() error
}
Runnable is required to implement by service.
type ServiceContainer ¶
type ServiceContainer struct {
// contains filtered or unexported fields
}
func NewServiceContainer ¶
func NewServiceContainer() *ServiceContainer
func (*ServiceContainer) Close ¶
func (c *ServiceContainer) Close()
Close stop all stoppable service. Panics if error occurs.
func (*ServiceContainer) GetService ¶
func (c *ServiceContainer) GetService(name string) Runnable
GetService return nil if no such service provided.
func (*ServiceContainer) Init ¶
func (c *ServiceContainer) Init()
Init create all service object by calling create function. Panics if error occurs.
func (*ServiceContainer) RegisterCreator ¶
func (c *ServiceContainer) RegisterCreator(name string, creator ServiceCreator)
RegisterCreator register service creator by name. Panics if duplicate name or creator is not valid.
func (*ServiceContainer) RegisterService ¶
func (c *ServiceContainer) RegisterService(name string, svc Runnable)
RegisterService register service by name. Panics if duplicate name.
func (*ServiceContainer) RunServices ¶
func (c *ServiceContainer) RunServices()
RunServices run service in seprate routine then wait all service to stop. Panics if Run return error.
type ServiceCreator ¶
type ServiceCreator struct {
closure.ObjectCreator
}
ServiceCreator used to create service object.
CreateFunc must be func() T or func() (T, error) T must implements Runnable. If T implements Stoppable, Stop will be called.
Receiver is optional If set, it must be *T
func NewServiceCreator ¶
func NewServiceCreator(createFunc interface{}, receiver interface{}) ServiceCreator
NewServiceCreator parameter CreateFunc must be func() T or func() (T, error). Receiver is optional, If set, it must be *T.