From c7b48b96d436082b0f627ed353a7bab87c3beff4 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Tue, 13 Jul 2021 09:54:08 +0100 Subject: [PATCH] chore: changes from review Signed-off-by: Richard Case --- pkg/provider/registry/errors.go | 12 ------------ pkg/provider/registry/registry.go | 10 ++++------ 2 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 pkg/provider/registry/errors.go diff --git a/pkg/provider/registry/errors.go b/pkg/provider/registry/errors.go deleted file mode 100644 index cefa6dc85..000000000 --- a/pkg/provider/registry/errors.go +++ /dev/null @@ -1,12 +0,0 @@ -package registry - -import "errors" - -var ( - // ErrDuplicatePlugin is an error for when plugin registration has been called multiple - // time for a plugin with the same name. - ErrDuplicatePlugin = errors.New("plugin with the same name has already been registered") - - // ErrPluginNotFound is an error when a plugin isn't found with a supplied name. - ErrPluginNotFound = errors.New("plugin not found") -) diff --git a/pkg/provider/registry/registry.go b/pkg/provider/registry/registry.go index d8687116e..3cc5fcf16 100644 --- a/pkg/provider/registry/registry.go +++ b/pkg/provider/registry/registry.go @@ -19,7 +19,7 @@ func RegisterProvider(name string, factory provider.Factory) error { defer pluginsLock.Unlock() if _, exists := plugins[name]; exists { - return ErrDuplicatePlugin + return fmt.Errorf("plugin %s has already been registered", name) } plugins[name] = factory @@ -37,7 +37,7 @@ func GetPluginInstance(ctx context.Context, name string, runtime *provider.Runti return factoryFunc(ctx, runtime) } - return nil, fmt.Errorf("getting plugin %s: %w", name, ErrPluginNotFound) + return nil, fmt.Errorf("plugin %s not found", name) } // ListPlugins returns a list of the plugin names that have been registered. @@ -45,11 +45,9 @@ func ListPlugins() []string { pluginsLock.RLock() defer pluginsLock.RUnlock() - names := make([]string, len(plugins)) - i := 0 + names := []string{} for name := range plugins { - names[i] = name - i++ + names = append(names, name) } return names