service_manager

package
v0.0.0-...-909db3f Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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.

type Stoppable

type Stoppable interface {
	Stop() error
}

Stoppable is optional to implement.

Jump to

Keyboard shortcuts

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