Service
Services in Gobs are any instances. All services will go through some stages as its life-cycles. The default life-cycles from gobs bootstrap follow the digram below:
stateDiagram-v2 classDef Run fill:#99ff99,color:#000000 class Start Run [*] --> Init Init --> OnSetup,Setup Init --> [*]: Error OnSetup,Setup --> Start OnSetup,Setup --> Stop: Error Start --> Stop Stop --> [*]
Each stage has specific responsibilities in bootstrap an service.
- Init: Set the dependencies of a service instance
- Setup: Configure the service after all of its dependencies are ready
- Start: Run the service after all of its dependencies are ready
- Stop: Stop the service if service has been setup after all others depended on its stopped
Initialization
The Init of services are called when gobs.Init(ctx) is called.
var _ gobs.InitService = (*API)(nil)
func (a *API) Init(ctx context.Context) (*gobs.ServiceLifeCycle, error) {
return &gobs.ServiceLifeCycle{}, nil
}The main function of Init of a service is to configure the dependencies of a service. The detail of configuration is in ServiceLifeCycle struct
Setup
The Setup of services are called when gobs.Setup(ctx) is called.
var _ gobs.SetupService = (*API)(nil)
func (a *API) Setup(ctx context.Context) (error) {
return nil
}If the Setup return any error, all other Setup of services which is pending will be rejected.
Start
The Start of services are called when gobs.Start(ctx) is called.
var _ gobs.StartService = (*API)(nil)
func (a *API) Start(ctx context.Context) (error) {
return nil
}If the Start return any error, all other Start of services which is pending will be rejected.
Start pending, the other will never be startedStop
The Stop of services are called when gobs.Stop(ctx) is called.
var _ gobs.StopService = (*API)(nil)
func (a *API) Stop(ctx context.Context) {
return
}Stop of a service fails, Gobs will try to process to the end