Setup plugin ids and dependencies
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
36
plugin/context.go
Normal file
36
plugin/context.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func NewContext(plugins map[PluginType][]interface{}) *InitContext {
|
||||
return &InitContext{
|
||||
plugins: plugins,
|
||||
}
|
||||
}
|
||||
|
||||
type InitContext struct {
|
||||
Root string
|
||||
Context context.Context
|
||||
Config interface{}
|
||||
|
||||
plugins map[PluginType][]interface{}
|
||||
}
|
||||
|
||||
func (i *InitContext) Get(t PluginType) (interface{}, error) {
|
||||
p := i.plugins[t]
|
||||
if len(p) == 0 {
|
||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||
}
|
||||
return p[0], nil
|
||||
}
|
||||
|
||||
func (i *InitContext) GetAll(t PluginType) ([]interface{}, error) {
|
||||
p, ok := i.plugins[t]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no plugins registered for %s", t)
|
||||
}
|
||||
return p, nil
|
||||
}
|
Reference in New Issue
Block a user