From dab0f3223f858072b8631d99771c6853c49e4dad Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 29 Oct 2019 12:29:21 +0000 Subject: [PATCH] Add Update/List endpoints to runtime --- runtime/default.go | 22 ++++++++++++++++++++++ runtime/runtime.go | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/runtime/default.go b/runtime/default.go index 9ebf7a06..953e83a5 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -252,6 +252,28 @@ func (r *runtime) Delete(s *Service) error { return nil } +func (r *runtime) Update(s *Service) error { + // delete the service + if err := r.Delete(s); err != nil { + return err + } + + // create new service + return r.Create(s) +} + +func (r *runtime) List() ([]*Service, error) { + var services []*Service + r.RLock() + defer r.RUnlock() + + for _, service := range r.services { + services = append(services, service.Service) + } + + return services, nil +} + func (r *runtime) Start() error { r.Lock() defer r.Unlock() diff --git a/runtime/runtime.go b/runtime/runtime.go index 63216867..0cb84802 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -7,6 +7,10 @@ type Runtime interface { Create(*Service, ...CreateOption) error // Remove a service Delete(*Service) error + // Update the service in place + Update(*Service) error + // List the managed services + List() ([]*Service, error) // starts the runtime Start() error // Shutdown the runtime @@ -36,6 +40,14 @@ func Delete(s *Service) error { return DefaultRuntime.Delete(s) } +func Update(s *Service) error { + return DefaultRuntime.Update(s) +} + +func List() ([]*Service, error) { + return DefaultRuntime.List() +} + func Start() error { return DefaultRuntime.Start() }