7 "github.com/hashicorp/go-plugin"
8 "github.com/hashicorp/go-plugin/examples/grpc/shared"
11 // Here is a real implementation of KV that writes to a local file with
12 // the key name and the contents are the value of the key.
15 func (KV) Put(key string, value []byte) error {
16 value = []byte(fmt.Sprintf("%s\n\nWritten from plugin-go-grpc", string(value)))
17 return ioutil.WriteFile("kv_"+key, value, 0644)
20 func (KV) Get(key string) ([]byte, error) {
21 return ioutil.ReadFile("kv_" + key)
25 plugin.Serve(&plugin.ServeConfig{
26 HandshakeConfig: shared.Handshake,
27 Plugins: map[string]plugin.Plugin{
28 "kv": &shared.KVPlugin{Impl: &KV{}},
31 // A non-nil value here enables gRPC serving for this plugin...
32 GRPCServer: plugin.DefaultGRPCServer,