OSDN Git Service

add package
[bytom/vapor.git] / vendor / github.com / hashicorp / go-plugin / examples / grpc / plugin-go-grpc / main.go
1 package main
2
3 import (
4         "fmt"
5         "io/ioutil"
6
7         "github.com/hashicorp/go-plugin"
8         "github.com/hashicorp/go-plugin/examples/grpc/shared"
9 )
10
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.
13 type KV struct{}
14
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)
18 }
19
20 func (KV) Get(key string) ([]byte, error) {
21         return ioutil.ReadFile("kv_" + key)
22 }
23
24 func main() {
25         plugin.Serve(&plugin.ServeConfig{
26                 HandshakeConfig: shared.Handshake,
27                 Plugins: map[string]plugin.Plugin{
28                         "kv": &shared.KVPlugin{Impl: &KV{}},
29                 },
30
31                 // A non-nil value here enables gRPC serving for this plugin...
32                 GRPCServer: plugin.DefaultGRPCServer,
33         })
34 }