4 "github.com/hashicorp/go-plugin/examples/grpc/proto"
5 "golang.org/x/net/context"
8 // GRPCClient is an implementation of KV that talks over RPC.
9 type GRPCClient struct{ client proto.KVClient }
11 func (m *GRPCClient) Put(key string, value []byte) error {
12 _, err := m.client.Put(context.Background(), &proto.PutRequest{
19 func (m *GRPCClient) Get(key string) ([]byte, error) {
20 resp, err := m.client.Get(context.Background(), &proto.GetRequest{
27 return resp.Value, nil
30 // Here is the gRPC server that GRPCClient talks to.
31 type GRPCServer struct {
32 // This is the real implementation
36 func (m *GRPCServer) Put(
38 req *proto.PutRequest) (*proto.Empty, error) {
39 return &proto.Empty{}, m.Impl.Put(req.Key, req.Value)
42 func (m *GRPCServer) Get(
44 req *proto.GetRequest) (*proto.GetResponse, error) {
45 v, err := m.Impl.Get(req.Key)
46 return &proto.GetResponse{Value: v}, err