1 // Package shared contains shared data between the host and plugins.
5 "golang.org/x/net/context"
6 "google.golang.org/grpc"
8 "github.com/hashicorp/go-plugin"
9 "github.com/hashicorp/go-plugin/examples/bidirectional/proto"
12 // Handshake is a common handshake that is shared by plugin and host.
13 var Handshake = plugin.HandshakeConfig{
15 MagicCookieKey: "BASIC_PLUGIN",
16 MagicCookieValue: "hello",
19 // PluginMap is the map of plugins we can dispense.
20 var PluginMap = map[string]plugin.Plugin{
21 "counter": &CounterPlugin{},
24 type AddHelper interface {
25 Sum(int64, int64) (int64, error)
28 // KV is the interface that we're exposing as a plugin.
29 type Counter interface {
30 Put(key string, value int64, a AddHelper) error
31 Get(key string) (int64, error)
34 // This is the implementation of plugin.Plugin so we can serve/consume this.
35 // We also implement GRPCPlugin so that this plugin can be served over
37 type CounterPlugin struct {
38 plugin.NetRPCUnsupportedPlugin
39 // Concrete implementation, written in Go. This is only used for plugins
40 // that are written in Go.
44 func (p *CounterPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
45 proto.RegisterCounterServer(s, &GRPCServer{
52 func (p *CounterPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
54 client: proto.NewCounterClient(c),
59 var _ plugin.GRPCPlugin = &CounterPlugin{}