github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/helper/pluginutils/loader/instance.go (about) 1 package loader 2 3 import plugin "github.com/hashicorp/go-plugin" 4 5 // PluginInstance wraps an instance of a plugin. If the plugin is external, it 6 // provides methods to retrieve the ReattachConfig and to kill the plugin. 7 type PluginInstance interface { 8 // Internal returns if the plugin is internal 9 Internal() bool 10 11 // Kill kills the plugin if it is external. It is safe to call on internal 12 // plugins. 13 Kill() 14 15 // ReattachConfig returns the ReattachConfig and whether the plugin is internal 16 // or not. If the second return value is false, no ReattachConfig is 17 // possible to return. 18 ReattachConfig() (config *plugin.ReattachConfig, canReattach bool) 19 20 // Plugin returns the wrapped plugin instance. 21 Plugin() interface{} 22 23 // Exited returns whether the plugin has exited 24 Exited() bool 25 26 // ApiVersion returns the API version to be used with the plugin 27 ApiVersion() string 28 } 29 30 // internalPluginInstance wraps an internal plugin 31 type internalPluginInstance struct { 32 instance interface{} 33 apiVersion string 34 } 35 36 func (p *internalPluginInstance) Internal() bool { return true } 37 func (p *internalPluginInstance) Kill() {} 38 func (p *internalPluginInstance) ReattachConfig() (*plugin.ReattachConfig, bool) { return nil, false } 39 func (p *internalPluginInstance) Plugin() interface{} { return p.instance } 40 func (p *internalPluginInstance) Exited() bool { return false } 41 func (p *internalPluginInstance) ApiVersion() string { return p.apiVersion } 42 43 // externalPluginInstance wraps an external plugin 44 type externalPluginInstance struct { 45 client *plugin.Client 46 instance interface{} 47 apiVersion string 48 } 49 50 func (p *externalPluginInstance) Internal() bool { return false } 51 func (p *externalPluginInstance) Plugin() interface{} { return p.instance } 52 func (p *externalPluginInstance) Exited() bool { return p.client.Exited() } 53 func (p *externalPluginInstance) ApiVersion() string { return p.apiVersion } 54 55 func (p *externalPluginInstance) ReattachConfig() (*plugin.ReattachConfig, bool) { 56 return p.client.ReattachConfig(), true 57 } 58 59 func (p *externalPluginInstance) Kill() { 60 p.client.Kill() 61 }