-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplugin.go
47 lines (40 loc) · 1.43 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package plugin
import (
"context"
"github.com/aperturerobotics/controllerbus/bus"
"github.com/aperturerobotics/controllerbus/controller"
)
// PluginGlobalVar is the global var in plugin bundles.
const PluginGlobalVar = "ControllerBusPlugin"
// Plugin is the top-level type exposed in a Hot binary.
type Plugin interface {
// UnloadHandler indicates plugin implements pre-plugin unload
UnloadHandler
// GetBinaryID returns the plugin binary ID.
// Usually the go.mod package name.
GetBinaryID() string
// GetBinaryVersion returns the plugin binary version
// Does not need to be semver (usually uses Go.mod versioning)
GetBinaryVersion() string
// NewPluginResolver constructs the resolver and inits the plugin.
// ctx is canceled when the plugin is about to be unloaded.
NewPluginResolver(ctx context.Context, bus bus.Bus) (PluginResolver, error)
}
// PluginResolver resolves types included in a binary.
type PluginResolver interface {
// FactoryResolver indicates this implements FactoryResolver.
controller.FactoryResolver
// UnloadHandler indicates resolver implements pre-plugin unload
UnloadHandler
}
// UnloadHandler is called before the plugin is unloaded.
type UnloadHandler interface {
// PrePluginUnload is called just before the plugin is unloaded.
//
// Unloading:
// 1. context is canceled.
// 2. PrePluginUnload called on all resolvers.
// 3. PrePluginUnload called on plugin
// 4. Unload of plugin
PrePluginUnload()
}