10 "github.com/hashicorp/go-plugin"
11 "github.com/hashicorp/go-plugin/examples/grpc/shared"
15 // We don't want to see the plugin logs.
16 log.SetOutput(ioutil.Discard)
18 // We're a host. Start by launching the plugin process.
19 client := plugin.NewClient(&plugin.ClientConfig{
20 HandshakeConfig: shared.Handshake,
21 Plugins: shared.PluginMap,
22 Cmd: exec.Command("sh", "-c", os.Getenv("KV_PLUGIN")),
23 AllowedProtocols: []plugin.Protocol{
24 plugin.ProtocolNetRPC, plugin.ProtocolGRPC},
29 rpcClient, err := client.Client()
31 fmt.Println("Error:", err.Error())
36 raw, err := rpcClient.Dispense("kv")
38 fmt.Println("Error:", err.Error())
42 // We should have a KV store now! This feels like a normal interface
43 // implementation but is in fact over an RPC connection.
48 result, err := kv.Get(os.Args[1])
50 fmt.Println("Error:", err.Error())
54 fmt.Println(string(result))
57 err := kv.Put(os.Args[1], []byte(os.Args[2]))
59 fmt.Println("Error:", err.Error())
64 fmt.Println("Please only use 'get' or 'put'")