-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
52 lines (44 loc) · 1.41 KB
/
interface.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
48
49
50
51
52
package v1
import (
"context"
goplugin "github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
)
// Handshake must be used by all plugins to ensure that the plugin
// and host are compatible.
var Handshake = goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "GATEWAYD_PLUGIN",
MagicCookieValue: "5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872",
}
// GetPluginMap returns the plugin map for the plugin.
func GetPluginMap(pluginName string) map[string]goplugin.Plugin {
return map[string]goplugin.Plugin{
pluginName: &Plugin{},
}
}
// GetPluginSetMap returns the PluginSet for the plugin.
func GetPluginSetMap(plugins map[string]goplugin.Plugin) goplugin.PluginSet {
pluginSet := goplugin.PluginSet{}
for pluginName, plugin := range plugins {
pluginSet[pluginName] = plugin
}
return pluginSet
}
// Plugin is the interface that all plugins must implement.
type Plugin struct {
goplugin.GRPCPlugin
goplugin.NetRPCUnsupportedPlugin
Impl struct {
GatewayDPluginServiceServer
}
}
// GRPCServer registers the plugin with the gRPC server.
func (p *Plugin) GRPCServer(b *goplugin.GRPCBroker, s *grpc.Server) error {
RegisterGatewayDPluginServiceServer(s, &p.Impl)
return nil
}
// GRPCClient returns the plugin client.
func (p *Plugin) GRPCClient(ctx context.Context, b *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return NewGatewayDPluginServiceClient(c), nil
}