From fb77d50f7156b68a0a2c094da1b68e89b9b24cbc Mon Sep 17 00:00:00 2001 From: Iwasaki Yudai Date: Thu, 27 Apr 2017 10:51:47 -0700 Subject: [PATCH] Add ServiceNames() to APIProject Issue Observed -------------- project.APIProject doesn't provide a method to get the service names define in a project. You cannot get service names when you use GetSreviceConfig() and other methods of the interface. Proposed Resolution ------------------- We could add a method GetServiceConfigs() which returns the *ServiceConfigs owned by the concrete struct (project.Project). However, since the strcut already has ServiceConfigs property, we cannot add a new method with the same name. In this commit, we add a new method just returns the list of service names instead of returning the *ServiceConfigs itself. Signed-off-by: Iwasaki Yudai --- project/interface.go | 1 + project/project.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/project/interface.go b/project/interface.go index 3356407c2..7fb2b6187 100644 --- a/project/interface.go +++ b/project/interface.go @@ -41,6 +41,7 @@ type APIProject interface { Containers(ctx context.Context, filter Filter, services ...string) ([]string, error) GetServiceConfig(service string) (*config.ServiceConfig, bool) + GetServiceNames() []string } // Filter holds filter element to filter containers diff --git a/project/project.go b/project/project.go index ef783120a..4c28a1366 100644 --- a/project/project.go +++ b/project/project.go @@ -546,6 +546,11 @@ func (p *Project) GetServiceConfig(name string) (*config.ServiceConfig, bool) { return p.ServiceConfigs.Get(name) } +// GetServiceNames returnes all service names in the project. +func (p *Project) GetServiceNames() []string { + return p.ServiceConfigs.Keys() +} + // IsNamedVolume returns whether the specified volume (string) is a named volume or not. func IsNamedVolume(volume string) bool { return !strings.HasPrefix(volume, ".") && !strings.HasPrefix(volume, "/") && !strings.HasPrefix(volume, "~")