appcore is a small lifecycle manager for Go services. Each component is run
in its own goroutine. When any component exits, every component receives a
Shutdown call and Wait waits for the complete shutdown.
mgr := appcore.NewServiceMgr(appcore.WithLogger(logger))
mgr.Add(apiService, databaseService, appcoreServices.NewSignalService())
if err := mgr.StartAllService(); err != nil {
return err
}
return mgr.Wait()A component implements:
type IComponent interface {
Init() error
Start() error
Shutdown()
Name() string
}Init calls are synchronous and ordered. No Start method runs unless every
component initialized successfully. Start should block for the service's
lifetime. Shutdown must cause its corresponding Start call to return.