add create/delete/start/stop to runtime
This commit is contained in:
parent
0fc4c180ee
commit
0cdfc7b9ea
@ -141,7 +141,7 @@ func (s *service) Wait() {
|
||||
s.running = false
|
||||
}
|
||||
|
||||
func (r *runtime) Register(s *Service) error {
|
||||
func (r *runtime) Create(s *Service) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
||||
@ -155,7 +155,19 @@ func (r *runtime) Register(s *Service) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *runtime) Run() error {
|
||||
func (r *runtime) Delete(s *Service) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
||||
if s, ok := r.services[s.Name]; ok {
|
||||
delete(r.services, s.Name)
|
||||
return s.Stop()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *runtime) Start() error {
|
||||
r.Lock()
|
||||
|
||||
// already running
|
||||
|
@ -4,9 +4,11 @@ package runtime
|
||||
// Runtime is a service runtime manager
|
||||
type Runtime interface {
|
||||
// Registers a service
|
||||
Register(*Service) error
|
||||
Create(*Service) error
|
||||
// Remove a service
|
||||
Delete(*Service) error
|
||||
// starts the runtime
|
||||
Run() error
|
||||
Start() error
|
||||
// Shutdown the runtime
|
||||
Stop() error
|
||||
}
|
||||
@ -26,12 +28,16 @@ var (
|
||||
DefaultRuntime = newRuntime()
|
||||
)
|
||||
|
||||
func Register(s *Service) error {
|
||||
return DefaultRuntime.Register(s)
|
||||
func Create(s *Service) error {
|
||||
return DefaultRuntime.Create(s)
|
||||
}
|
||||
|
||||
func Run() error {
|
||||
return DefaultRuntime.Run()
|
||||
func Delete(s *Service) error {
|
||||
return DefaultRuntime.Delete(s)
|
||||
}
|
||||
|
||||
func Start() error {
|
||||
return DefaultRuntime.Start()
|
||||
}
|
||||
|
||||
func Stop() error {
|
||||
|
Loading…
Reference in New Issue
Block a user