9 hclog "github.com/hashicorp/go-hclog"
10 "github.com/hashicorp/go-plugin"
11 "github.com/hashicorp/go-plugin/examples/basic/commons"
15 // Create an hclog.Logger
16 logger := hclog.New(&hclog.LoggerOptions{
22 // We're a host! Start by launching the plugin process.
23 client := plugin.NewClient(&plugin.ClientConfig{
24 HandshakeConfig: handshakeConfig,
26 Cmd: exec.Command("./plugin/greeter"),
32 rpcClient, err := client.Client()
38 raw, err := rpcClient.Dispense("greeter")
43 // We should have a Greeter now! This feels like a normal interface
44 // implementation but is in fact over an RPC connection.
45 greeter := raw.(example.Greeter)
46 fmt.Println(greeter.Greet())
49 // handshakeConfigs are used to just do a basic handshake between
50 // a plugin and host. If the handshake fails, a user friendly error is shown.
51 // This prevents users from executing bad plugins or executing a plugin
52 // directory. It is a UX feature, not a security feature.
53 var handshakeConfig = plugin.HandshakeConfig{
55 MagicCookieKey: "BASIC_PLUGIN",
56 MagicCookieValue: "hello",
59 // pluginMap is the map of plugins we can dispense.
60 var pluginMap = map[string]plugin.Plugin{
61 "greeter": &example.GreeterPlugin{},