Update plugin factory definitions to use custom type
This commit is contained in:
parent
392ad6d3b7
commit
7357fa4017
@ -29,7 +29,7 @@ func init() {
|
|||||||
|
|
||||||
func Factory(
|
func Factory(
|
||||||
cmd *exec.Cmd, // Plugin command to run
|
cmd *exec.Cmd, // Plugin command to run
|
||||||
) func(hclog.Logger) (p *Plugin, err error) {
|
) PluginRegistration {
|
||||||
return func(log hclog.Logger) (p *Plugin, err error) {
|
return func(log hclog.Logger) (p *Plugin, err error) {
|
||||||
// We have to copy the command because go-plugin will set some
|
// We have to copy the command because go-plugin will set some
|
||||||
// fields on it.
|
// fields on it.
|
||||||
@ -46,6 +46,9 @@ func Factory(
|
|||||||
|
|
||||||
// Connect to the plugin
|
// Connect to the plugin
|
||||||
client := plugin.NewClient(config)
|
client := plugin.NewClient(config)
|
||||||
|
|
||||||
|
// If we encounter any errors during setup, automatically
|
||||||
|
// kill the client
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Kill()
|
client.Kill()
|
||||||
@ -68,10 +71,13 @@ func Factory(
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
info, ok := raw.(component.PluginInfo)
|
info, ok := raw.(component.PluginInfo)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("failed to load plugin information interface",
|
log.Error("cannot load plugin info component",
|
||||||
"plugin", cmd.Path)
|
"plugin", cmd.Path)
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("failed to load plugin information interface")
|
||||||
}
|
}
|
||||||
|
|
||||||
p = &Plugin{
|
p = &Plugin{
|
||||||
@ -104,7 +110,7 @@ func Factory(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// BuiltinFactory creates a factory for a built-in plugin type.
|
// BuiltinFactory creates a factory for a built-in plugin type.
|
||||||
func BuiltinFactory(name string) func(hclog.Logger) (p *Plugin, err error) {
|
func BuiltinFactory(name string) PluginRegistration {
|
||||||
cmd := exec.Command(exePath, "plugin-run", name)
|
cmd := exec.Command(exePath, "plugin-run", name)
|
||||||
|
|
||||||
// For non-windows systems, we attach stdout/stderr as extra fds
|
// For non-windows systems, we attach stdout/stderr as extra fds
|
||||||
@ -120,7 +126,7 @@ func RubyFactory(
|
|||||||
rubyClient plugin.ClientProtocol,
|
rubyClient plugin.ClientProtocol,
|
||||||
name string,
|
name string,
|
||||||
typ component.Type,
|
typ component.Type,
|
||||||
) func(hclog.Logger) (p *Plugin, err error) {
|
) PluginRegistration {
|
||||||
return func(log hclog.Logger) (*Plugin, error) {
|
return func(log hclog.Logger) (*Plugin, error) {
|
||||||
return &Plugin{
|
return &Plugin{
|
||||||
Builtin: false,
|
Builtin: false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user