Move plugin context events into separate plugin

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2021-08-05 21:50:40 -07:00
parent 7d4891783a
commit 0a0621bb47
19 changed files with 137 additions and 16 deletions

View File

@@ -34,7 +34,9 @@ type InitContext struct {
Config interface{}
Address string
TTRPCAddress string
Events *exchange.Exchange
// deprecated: will be removed in 2.0, use plugin.EventType
Events *exchange.Exchange
Meta *Meta // plugins can fill in metadata at init.
@@ -135,6 +137,19 @@ func (i *InitContext) GetAll() []*Plugin {
return i.plugins.ordered
}
// GetByID returns the plugin of the given type and ID
func (i *InitContext) GetByID(t Type, id string) (interface{}, error) {
ps, err := i.GetByType(t)
if err != nil {
return nil, err
}
p, ok := ps[id]
if !ok {
return nil, errors.Wrapf(errdefs.ErrNotFound, "no %s plugins with id %s", t, id)
}
return p.Instance()
}
// GetByType returns all plugins with the specific type.
func (i *InitContext) GetByType(t Type) (map[string]*Plugin, error) {
p, ok := i.plugins.byTypeAndID[t]