Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pkg/epp/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ limitations under the License.

package plugins

import "context"
import (
"context"
"fmt"
)

// Plugin defines the interface for a plugin.
// This interface should be embedded in all plugins across the code.
Expand Down Expand Up @@ -50,3 +53,18 @@ type HandlePlugins interface {
// GetAllPluginsWithNames returns all of the known plugins with their names
GetAllPluginsWithNames() map[string]Plugin
}

// PluginByType retrieves the specified plugin by name and verifies its type
func PluginByType[P Plugin](handlePlugins HandlePlugins, name string) (P, error) {
var zero P

rawPlugin := handlePlugins.Plugin(name)
if rawPlugin == nil {
return zero, fmt.Errorf("there was no plugin with the name '%s' defined", name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit1:

Suggested change
return zero, fmt.Errorf("there was no plugin with the name '%s' defined", name)
return zero, fmt.Errorf("there is no plugin with the name '%s' defined", name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
thePlugin, ok := rawPlugin.(P)
if !ok {
return zero, fmt.Errorf("the plugin with the name '%s' was not an instance of %T", name, zero)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit2:

Suggested change
return zero, fmt.Errorf("the plugin with the name '%s' was not an instance of %T", name, zero)
return zero, fmt.Errorf("the plugin with the name '%s' is not an instance of %T", name, zero)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
return thePlugin, nil
}