6 "github.com/hashicorp/go-hclog"
7 "github.com/hashicorp/go-plugin"
8 "github.com/hashicorp/go-plugin/examples/basic/commons"
11 // Here is a real implementation of Greeter
12 type GreeterHello struct {
16 func (g *GreeterHello) Greet() string {
17 g.logger.Debug("message from GreeterHello.Greet")
21 // handshakeConfigs are used to just do a basic handshake between
22 // a plugin and host. If the handshake fails, a user friendly error is shown.
23 // This prevents users from executing bad plugins or executing a plugin
24 // directory. It is a UX feature, not a security feature.
25 var handshakeConfig = plugin.HandshakeConfig{
27 MagicCookieKey: "BASIC_PLUGIN",
28 MagicCookieValue: "hello",
32 logger := hclog.New(&hclog.LoggerOptions{
38 greeter := &GreeterHello{
41 // pluginMap is the map of plugins we can dispense.
42 var pluginMap = map[string]plugin.Plugin{
43 "greeter": &example.GreeterPlugin{Impl: greeter},
46 logger.Debug("message from plugin", "foo", "bar")
48 plugin.Serve(&plugin.ServeConfig{
49 HandshakeConfig: handshakeConfig,