remove unused code from vendor

This commit is contained in:
bergquist
2018-01-19 09:54:22 +01:00
parent e023f79c5a
commit 7ed643f302
6531 changed files with 6 additions and 2907556 deletions
-12
View File
@@ -1,12 +0,0 @@
# go-plugin Documentation
This directory contains documentation and guides for `go-plugin` and how
to integrate it into your projects. It is assumed that you know _what_
go-plugin is and _why_ you would want to use it. If not, please see the
[README](https://github.com/hashicorp/go-plugin/blob/master/README.md).
## Table of Contents
**[Writing Plugins Without Go](https://github.com/hashicorp/go-plugin/blob/master/docs/guide-plugin-write-non-go.md).**
This shows how to write a plugin using a programming language other than
Go.
-150
View File
@@ -1,150 +0,0 @@
# Writing Plugins Without Go
This guide explains how to write a go-plugin compatible plugin using
a programming language other than Go. go-plugin supports plugins using
[gRPC](http://www.grpc.io). This makes it relatively simple to write plugins
using other languages!
Minimal knowledge about gRPC is assumed. We recommend reading the
[gRPC Go Tutorial](http://www.grpc.io/docs/tutorials/basic/go.html). This
alone is enough gRPC knowledge to continue.
This guide will implement the kv example in Python.
Full source code for the examples present in this guide
[is available in the examples/grpc folder](https://github.com/hashicorp/go-plugin/tree/master/examples/grpc).
## 1. Implement the Service
The first step is to implement the gRPC server for the protocol buffers
service that your plugin defines. This is a standard gRPC server.
For the KV service, the service looks like this:
```proto
service KV {
rpc Get(GetRequest) returns (GetResponse);
rpc Put(PutRequest) returns (Empty);
}
```
We can implement that using Python as easily as:
```python
class KVServicer(kv_pb2_grpc.KVServicer):
"""Implementation of KV service."""
def Get(self, request, context):
filename = "kv_"+request.key
with open(filename, 'r') as f:
result = kv_pb2.GetResponse()
result.value = f.read()
return result
def Put(self, request, context):
filename = "kv_"+request.key
value = "{0}\n\nWritten from plugin-python".format(request.value)
with open(filename, 'w') as f:
f.write(value)
return kv_pb2.Empty()
```
Great! With that, we have a fully functioning implementation of the service.
You can test this using standard gRPC testing mechanisms.
## 2. Serve the Service
Next, we need to create a gRPC server and serve the service we just made.
In Python:
```python
# Make the server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
# Add our service
kv_pb2_grpc.add_KVServicer_to_server(KVServicer(), server)
# Listen on a port
server.add_insecure_port(':1234')
# Start
server.start()
```
You can listen on any TCP address or Unix domain socket. go-plugin does
assume that connections are reliable (local), so you should not serve
your plugin across the network.
## 3. Add the gRPC Health Checking Service
go-plugin requires the
[gRPC Health Checking Service](https://github.com/grpc/grpc/blob/master/doc/health-checking.md)
to be registered on your server. You must register the status of "plugin" to be SERVING.
The health checking service is used by go-plugin to determine if everything
is healthy with the connection. If you don't implement this service, your
process may be abruptly restarted and your plugins are likely to be unreliable.
```
health = HealthServicer()
health.set("plugin", health_pb2.HealthCheckResponse.ServingStatus.Value('SERVING'))
health_pb2_grpc.add_HealthServicer_to_server(health, server)
```
## 4. Output Handshake Information
The final step is to output the handshake information to stdout. go-plugin
reads a single line from stdout to determine how to connect to your plugin,
what protocol it is using, etc.
The structure is:
```
CORE-PROTOCOL-VERSION | APP-PROTOCOL-VERSION | NETWORK-TYPE | NETWORK-ADDR | PROTOCOL
```
Where:
* `CORE-PROTOCOL-VERSION` is the protocol version for go-plugin itself.
The current value is `1`. Please use this value. Any other value will
cause your plugin to not load.
* `APP-PROTOCOL-VERSION` is the protocol version for the application data.
This is determined by the application. You must reference the documentation
for your application to determine the desired value.
* `NETWORK-TYPE` and `NETWORK-ADDR` are the networking information for
connecting to this plugin. The type must be "unix" or "tcp". The address
is a path to the Unix socket for "unix" and an IP address for "tcp".
* `PROTOCOL` is the named protocol that the connection will use. If this
is omitted (older versions), this is "netrpc" for Go net/rpc. This can
also be "grpc". This is the protocol that the plugin wants to speak to
the host process with.
For our example that is:
```
1|1|tcp|127.0.0.1:1234|grpc
```
The only element you'll have to be careful about is the second one (the
`APP-PROTOCOL-VERISON`). This will depend on the application you're
building a plugin for. Please reference their documentation for more
information.
## 5. Done!
And we're done!
Configure the host application (the application you're writing a plugin
for) to execute your Python application. Configuring plugins is specific
to the host application.
For our example, we used an environmental variable, and it looks like this:
```sh
$ export KV_PLUGIN="python plugin.py"
```
-63
View File
@@ -1,63 +0,0 @@
# go-plugin Internals
This section discusses the internals of how go-plugin works.
go-plugin operates by either _serving_ a plugin or being a _client_
connecting to a remote plugin. The "client" is the host process or the
process that itself uses plugins. The "server" is the plugin process.
For a server:
1. Output handshake to stdout
2. Wait for connection on control address
3. Serve plugins over control address
For a client:
1. Launch a plugin binary
2. Read and verify handshake from plugin stdout
3. Connect to plugin control address using desired protocol
4. Dispense plugins using control connection
## Handshake
The handshake is the initial communication between a plugin and a host
process to determine how the host process can connect and communicate to
the plugin. This handshake is done over the plugin process's stdout.
The `go-plugin` library itself handles the handshake when using the
`Server` to serve a plugin. **You do not need to understand the internals
of the handshake,** unless you're building a go-plugin compatible plugin
in another language.
The handshake is a single line of data terminated with a newline character
`\n`. It looks like the following:
```
1|3|unix|/path/to/socket|grpc
```
The structure is:
```
CORE-PROTOCOL-VERSION | APP-PROTOCOL-VERSION | NETWORK-TYPE | NETWORK-ADDR | PROTOCOL
```
Where:
* `CORE-PROTOCOL-VERSION` is the protocol version for go-plugin itself.
The current value is `1`. Please use this value. Any other value will
cause your plugin to not load.
* `APP-PROTOCOL-VERSION` is the protocol version for the application data.
This is determined by the application. You must reference the documentation
for your application to determine the desired value.
* `NETWORK-TYPE` and `NETWORK-ADDR` are the networking information for
connecting to this plugin. The type must be "unix" or "tcp". The address
is a path to the Unix socket for "unix" and an IP address for "tcp".
* `PROTOCOL` is the named protocol that the connection will use. If this
is omitted (older versions), this is "netrpc" for Go net/rpc. This can
also be "grpc". This is the protocol that the plugin wants to speak to
the host process with.
@@ -1,3 +0,0 @@
# Ignore binaries
plugin/greeter
basic
-14
View File
@@ -1,14 +0,0 @@
Plugin Example
--------------
Compile the plugin itself via:
go build -o ./plugin/greeter ./plugin/greeter_impl.go
Compile this driver via:
go build -o basic .
You can then launch the plugin sample via:
./basic
@@ -1,62 +0,0 @@
package example
import (
"net/rpc"
"github.com/hashicorp/go-plugin"
)
// Greeter is the interface that we're exposing as a plugin.
type Greeter interface {
Greet() string
}
// Here is an implementation that talks over RPC
type GreeterRPC struct{ client *rpc.Client }
func (g *GreeterRPC) Greet() string {
var resp string
err := g.client.Call("Plugin.Greet", new(interface{}), &resp)
if err != nil {
// You usually want your interfaces to return errors. If they don't,
// there isn't much other choice here.
panic(err)
}
return resp
}
// Here is the RPC server that GreeterRPC talks to, conforming to
// the requirements of net/rpc
type GreeterRPCServer struct {
// This is the real implementation
Impl Greeter
}
func (s *GreeterRPCServer) Greet(args interface{}, resp *string) error {
*resp = s.Impl.Greet()
return nil
}
// This is the implementation of plugin.Plugin so we can serve/consume this
//
// This has two methods: Server must return an RPC server for this plugin
// type. We construct a GreeterRPCServer for this.
//
// Client must return an implementation of our interface that communicates
// over an RPC client. We return GreeterRPC for this.
//
// Ignore MuxBroker. That is used to create more multiplexed streams on our
// plugin connection and is a more advanced use case.
type GreeterPlugin struct {
// Impl Injection
Impl Greeter
}
func (p *GreeterPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
return &GreeterRPCServer{Impl: p.Impl}, nil
}
func (GreeterPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &GreeterRPC{client: c}, nil
}
-62
View File
@@ -1,62 +0,0 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-plugin/examples/basic/commons"
)
func main() {
// Create an hclog.Logger
logger := hclog.New(&hclog.LoggerOptions{
Name: "plugin",
Output: os.Stdout,
Level: hclog.Debug,
})
// We're a host! Start by launching the plugin process.
client := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
Cmd: exec.Command("./plugin/greeter"),
Logger: logger,
})
defer client.Kill()
// Connect via RPC
rpcClient, err := client.Client()
if err != nil {
log.Fatal(err)
}
// Request the plugin
raw, err := rpcClient.Dispense("greeter")
if err != nil {
log.Fatal(err)
}
// We should have a Greeter now! This feels like a normal interface
// implementation but is in fact over an RPC connection.
greeter := raw.(example.Greeter)
fmt.Println(greeter.Greet())
}
// handshakeConfigs are used to just do a basic handshake between
// a plugin and host. If the handshake fails, a user friendly error is shown.
// This prevents users from executing bad plugins or executing a plugin
// directory. It is a UX feature, not a security feature.
var handshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "BASIC_PLUGIN",
MagicCookieValue: "hello",
}
// pluginMap is the map of plugins we can dispense.
var pluginMap = map[string]plugin.Plugin{
"greeter": &example.GreeterPlugin{},
}
@@ -1,52 +0,0 @@
package main
import (
"os"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-plugin/examples/basic/commons"
)
// Here is a real implementation of Greeter
type GreeterHello struct {
logger hclog.Logger
}
func (g *GreeterHello) Greet() string {
g.logger.Debug("message from GreeterHello.Greet")
return "Hello!"
}
// handshakeConfigs are used to just do a basic handshake between
// a plugin and host. If the handshake fails, a user friendly error is shown.
// This prevents users from executing bad plugins or executing a plugin
// directory. It is a UX feature, not a security feature.
var handshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "BASIC_PLUGIN",
MagicCookieValue: "hello",
}
func main() {
logger := hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
Output: os.Stderr,
JSONFormat: true,
})
greeter := &GreeterHello{
logger: logger,
}
// pluginMap is the map of plugins we can dispense.
var pluginMap = map[string]plugin.Plugin{
"greeter": &example.GreeterPlugin{Impl: greeter},
}
logger.Debug("message from plugin", "foo", "bar")
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: handshakeConfig,
Plugins: pluginMap,
})
}
@@ -1,5 +0,0 @@
*.pyc
kv
kv-*
kv_*
!kv_*.py
-71
View File
@@ -1,71 +0,0 @@
# KV Example
This example builds a simple key/value store CLI where the mechanism
for storing and retrieving keys is pluggable. To build this example:
```sh
# This builds the main CLI
$ go build -o kv
# This builds the plugin written in Go
$ go build -o kv-go-grpc ./plugin-go-grpc
# This tells the KV binary to use the "kv-go-grpc" binary
$ export KV_PLUGIN="./kv-go-grpc"
# Read and write
$ ./kv put hello world
$ ./kv get hello
world
```
### Plugin: plugin-go-grpc
This plugin uses gRPC to serve a plugin that is written in Go:
```
# This builds the plugin written in Go
$ go build -o kv-go-grpc ./plugin-go-grpc
# This tells the KV binary to use the "kv-go-grpc" binary
$ export KV_PLUGIN="./kv-go-grpc"
```
### Plugin: plugin-go-netrpc
This plugin uses the builtin Go net/rpc mechanism to serve the plugin:
```
# This builds the plugin written in Go
$ go build -o kv-go-netrpc ./plugin-go-netrpc
# This tells the KV binary to use the "kv-go-netrpc" binary
$ export KV_PLUGIN="./kv-go-netrpc"
```
### Plugin: plugin-python
This plugin is written in Python:
```
$ export KV_PLUGIN="python plugin-python/plugin.py"
```
## Updating the Protocol
If you update the protocol buffers file, you can regenerate the file
using the following command from this directory. You do not need to run
this if you're just trying the example.
For Go:
```sh
$ protoc -I proto/ proto/kv.proto --go_out=plugins=grpc:proto/
```
For Python:
```sh
$ python -m grpc_tools.protoc -I ./proto/ --python_out=./plugin-python/ --grpc_python_out=./plugin-python/ ./proto/kv.proto
```
-67
View File
@@ -1,67 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-plugin/examples/grpc/shared"
)
func main() {
// We don't want to see the plugin logs.
log.SetOutput(ioutil.Discard)
// We're a host. Start by launching the plugin process.
client := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: shared.Handshake,
Plugins: shared.PluginMap,
Cmd: exec.Command("sh", "-c", os.Getenv("KV_PLUGIN")),
AllowedProtocols: []plugin.Protocol{
plugin.ProtocolNetRPC, plugin.ProtocolGRPC},
})
defer client.Kill()
// Connect via RPC
rpcClient, err := client.Client()
if err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
}
// Request the plugin
raw, err := rpcClient.Dispense("kv")
if err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
}
// We should have a KV store now! This feels like a normal interface
// implementation but is in fact over an RPC connection.
kv := raw.(shared.KV)
os.Args = os.Args[1:]
switch os.Args[0] {
case "get":
result, err := kv.Get(os.Args[1])
if err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
}
fmt.Println(string(result))
case "put":
err := kv.Put(os.Args[1], []byte(os.Args[2]))
if err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
}
default:
fmt.Println("Please only use 'get' or 'put'")
os.Exit(1)
}
}
@@ -1,34 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-plugin/examples/grpc/shared"
)
// Here is a real implementation of KV that writes to a local file with
// the key name and the contents are the value of the key.
type KV struct{}
func (KV) Put(key string, value []byte) error {
value = []byte(fmt.Sprintf("%s\n\nWritten from plugin-go-grpc", string(value)))
return ioutil.WriteFile("kv_"+key, value, 0644)
}
func (KV) Get(key string) ([]byte, error) {
return ioutil.ReadFile("kv_" + key)
}
func main() {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: shared.Handshake,
Plugins: map[string]plugin.Plugin{
"kv": &shared.KVPlugin{Impl: &KV{}},
},
// A non-nil value here enables gRPC serving for this plugin...
GRPCServer: plugin.DefaultGRPCServer,
})
}
@@ -1,31 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-plugin/examples/grpc/shared"
)
// Here is a real implementation of KV that writes to a local file with
// the key name and the contents are the value of the key.
type KV struct{}
func (KV) Put(key string, value []byte) error {
value = []byte(fmt.Sprintf("%s\n\nWritten from plugin-go-netrpc", string(value)))
return ioutil.WriteFile("kv_"+key, value, 0644)
}
func (KV) Get(key string) ([]byte, error) {
return ioutil.ReadFile("kv_" + key)
}
func main() {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: shared.Handshake,
Plugins: map[string]plugin.Plugin{
"kv": &shared.KVPlugin{Impl: &KV{}},
},
})
}
@@ -1,317 +0,0 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: kv.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='kv.proto',
package='proto',
syntax='proto3',
serialized_pb=_b('\n\x08kv.proto\x12\x05proto\"\x19\n\nGetRequest\x12\x0b\n\x03key\x18\x01 \x01(\t\"\x1c\n\x0bGetResponse\x12\r\n\x05value\x18\x01 \x01(\x0c\"(\n\nPutRequest\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x0c\"\x07\n\x05\x45mpty2Z\n\x02KV\x12,\n\x03Get\x12\x11.proto.GetRequest\x1a\x12.proto.GetResponse\x12&\n\x03Put\x12\x11.proto.PutRequest\x1a\x0c.proto.Emptyb\x06proto3')
)
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
_GETREQUEST = _descriptor.Descriptor(
name='GetRequest',
full_name='proto.GetRequest',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='key', full_name='proto.GetRequest.key', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=19,
serialized_end=44,
)
_GETRESPONSE = _descriptor.Descriptor(
name='GetResponse',
full_name='proto.GetResponse',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='proto.GetResponse.value', index=0,
number=1, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=46,
serialized_end=74,
)
_PUTREQUEST = _descriptor.Descriptor(
name='PutRequest',
full_name='proto.PutRequest',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='key', full_name='proto.PutRequest.key', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='value', full_name='proto.PutRequest.value', index=1,
number=2, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=76,
serialized_end=116,
)
_EMPTY = _descriptor.Descriptor(
name='Empty',
full_name='proto.Empty',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=118,
serialized_end=125,
)
DESCRIPTOR.message_types_by_name['GetRequest'] = _GETREQUEST
DESCRIPTOR.message_types_by_name['GetResponse'] = _GETRESPONSE
DESCRIPTOR.message_types_by_name['PutRequest'] = _PUTREQUEST
DESCRIPTOR.message_types_by_name['Empty'] = _EMPTY
GetRequest = _reflection.GeneratedProtocolMessageType('GetRequest', (_message.Message,), dict(
DESCRIPTOR = _GETREQUEST,
__module__ = 'kv_pb2'
# @@protoc_insertion_point(class_scope:proto.GetRequest)
))
_sym_db.RegisterMessage(GetRequest)
GetResponse = _reflection.GeneratedProtocolMessageType('GetResponse', (_message.Message,), dict(
DESCRIPTOR = _GETRESPONSE,
__module__ = 'kv_pb2'
# @@protoc_insertion_point(class_scope:proto.GetResponse)
))
_sym_db.RegisterMessage(GetResponse)
PutRequest = _reflection.GeneratedProtocolMessageType('PutRequest', (_message.Message,), dict(
DESCRIPTOR = _PUTREQUEST,
__module__ = 'kv_pb2'
# @@protoc_insertion_point(class_scope:proto.PutRequest)
))
_sym_db.RegisterMessage(PutRequest)
Empty = _reflection.GeneratedProtocolMessageType('Empty', (_message.Message,), dict(
DESCRIPTOR = _EMPTY,
__module__ = 'kv_pb2'
# @@protoc_insertion_point(class_scope:proto.Empty)
))
_sym_db.RegisterMessage(Empty)
try:
# THESE ELEMENTS WILL BE DEPRECATED.
# Please use the generated *_pb2_grpc.py files instead.
import grpc
from grpc.beta import implementations as beta_implementations
from grpc.beta import interfaces as beta_interfaces
from grpc.framework.common import cardinality
from grpc.framework.interfaces.face import utilities as face_utilities
class KVStub(object):
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.Get = channel.unary_unary(
'/proto.KV/Get',
request_serializer=GetRequest.SerializeToString,
response_deserializer=GetResponse.FromString,
)
self.Put = channel.unary_unary(
'/proto.KV/Put',
request_serializer=PutRequest.SerializeToString,
response_deserializer=Empty.FromString,
)
class KVServicer(object):
def Get(self, request, context):
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def Put(self, request, context):
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_KVServicer_to_server(servicer, server):
rpc_method_handlers = {
'Get': grpc.unary_unary_rpc_method_handler(
servicer.Get,
request_deserializer=GetRequest.FromString,
response_serializer=GetResponse.SerializeToString,
),
'Put': grpc.unary_unary_rpc_method_handler(
servicer.Put,
request_deserializer=PutRequest.FromString,
response_serializer=Empty.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'proto.KV', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
class BetaKVServicer(object):
"""The Beta API is deprecated for 0.15.0 and later.
It is recommended to use the GA API (classes and functions in this
file not marked beta) for all further purposes. This class was generated
only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
def Get(self, request, context):
context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
def Put(self, request, context):
context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
class BetaKVStub(object):
"""The Beta API is deprecated for 0.15.0 and later.
It is recommended to use the GA API (classes and functions in this
file not marked beta) for all further purposes. This class was generated
only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
def Get(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
raise NotImplementedError()
Get.future = None
def Put(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
raise NotImplementedError()
Put.future = None
def beta_create_KV_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None):
"""The Beta API is deprecated for 0.15.0 and later.
It is recommended to use the GA API (classes and functions in this
file not marked beta) for all further purposes. This function was
generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
request_deserializers = {
('proto.KV', 'Get'): GetRequest.FromString,
('proto.KV', 'Put'): PutRequest.FromString,
}
response_serializers = {
('proto.KV', 'Get'): GetResponse.SerializeToString,
('proto.KV', 'Put'): Empty.SerializeToString,
}
method_implementations = {
('proto.KV', 'Get'): face_utilities.unary_unary_inline(servicer.Get),
('proto.KV', 'Put'): face_utilities.unary_unary_inline(servicer.Put),
}
server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout)
return beta_implementations.server(method_implementations, options=server_options)
def beta_create_KV_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None):
"""The Beta API is deprecated for 0.15.0 and later.
It is recommended to use the GA API (classes and functions in this
file not marked beta) for all further purposes. This function was
generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
request_serializers = {
('proto.KV', 'Get'): GetRequest.SerializeToString,
('proto.KV', 'Put'): PutRequest.SerializeToString,
}
response_deserializers = {
('proto.KV', 'Get'): GetResponse.FromString,
('proto.KV', 'Put'): Empty.FromString,
}
cardinalities = {
'Get': cardinality.Cardinality.UNARY_UNARY,
'Put': cardinality.Cardinality.UNARY_UNARY,
}
stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size)
return beta_implementations.dynamic_stub(channel, 'proto.KV', cardinalities, options=stub_options)
except ImportError:
pass
# @@protoc_insertion_point(module_scope)
@@ -1,55 +0,0 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc
import kv_pb2 as kv__pb2
class KVStub(object):
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.Get = channel.unary_unary(
'/proto.KV/Get',
request_serializer=kv__pb2.GetRequest.SerializeToString,
response_deserializer=kv__pb2.GetResponse.FromString,
)
self.Put = channel.unary_unary(
'/proto.KV/Put',
request_serializer=kv__pb2.PutRequest.SerializeToString,
response_deserializer=kv__pb2.Empty.FromString,
)
class KVServicer(object):
def Get(self, request, context):
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def Put(self, request, context):
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_KVServicer_to_server(servicer, server):
rpc_method_handlers = {
'Get': grpc.unary_unary_rpc_method_handler(
servicer.Get,
request_deserializer=kv__pb2.GetRequest.FromString,
response_serializer=kv__pb2.GetResponse.SerializeToString,
),
'Put': grpc.unary_unary_rpc_method_handler(
servicer.Put,
request_deserializer=kv__pb2.PutRequest.FromString,
response_serializer=kv__pb2.Empty.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'proto.KV', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
-229
View File
@@ -1,229 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: kv.proto
/*
Package proto is a generated protocol buffer package.
It is generated from these files:
kv.proto
It has these top-level messages:
GetRequest
GetResponse
PutRequest
Empty
*/
package proto
import proto1 "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto1.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto1.ProtoPackageIsVersion2 // please upgrade the proto package
type GetRequest struct {
Key string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
}
func (m *GetRequest) Reset() { *m = GetRequest{} }
func (m *GetRequest) String() string { return proto1.CompactTextString(m) }
func (*GetRequest) ProtoMessage() {}
func (*GetRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *GetRequest) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
type GetResponse struct {
Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
}
func (m *GetResponse) Reset() { *m = GetResponse{} }
func (m *GetResponse) String() string { return proto1.CompactTextString(m) }
func (*GetResponse) ProtoMessage() {}
func (*GetResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *GetResponse) GetValue() []byte {
if m != nil {
return m.Value
}
return nil
}
type PutRequest struct {
Key string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
}
func (m *PutRequest) Reset() { *m = PutRequest{} }
func (m *PutRequest) String() string { return proto1.CompactTextString(m) }
func (*PutRequest) ProtoMessage() {}
func (*PutRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *PutRequest) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *PutRequest) GetValue() []byte {
if m != nil {
return m.Value
}
return nil
}
type Empty struct {
}
func (m *Empty) Reset() { *m = Empty{} }
func (m *Empty) String() string { return proto1.CompactTextString(m) }
func (*Empty) ProtoMessage() {}
func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func init() {
proto1.RegisterType((*GetRequest)(nil), "proto.GetRequest")
proto1.RegisterType((*GetResponse)(nil), "proto.GetResponse")
proto1.RegisterType((*PutRequest)(nil), "proto.PutRequest")
proto1.RegisterType((*Empty)(nil), "proto.Empty")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for KV service
type KVClient interface {
Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error)
Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*Empty, error)
}
type kVClient struct {
cc *grpc.ClientConn
}
func NewKVClient(cc *grpc.ClientConn) KVClient {
return &kVClient{cc}
}
func (c *kVClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) {
out := new(GetResponse)
err := grpc.Invoke(ctx, "/proto.KV/Get", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *kVClient) Put(ctx context.Context, in *PutRequest, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := grpc.Invoke(ctx, "/proto.KV/Put", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for KV service
type KVServer interface {
Get(context.Context, *GetRequest) (*GetResponse, error)
Put(context.Context, *PutRequest) (*Empty, error)
}
func RegisterKVServer(s *grpc.Server, srv KVServer) {
s.RegisterService(&_KV_serviceDesc, srv)
}
func _KV_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KVServer).Get(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.KV/Get",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KVServer).Get(ctx, req.(*GetRequest))
}
return interceptor(ctx, in, info, handler)
}
func _KV_Put_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PutRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(KVServer).Put(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/proto.KV/Put",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(KVServer).Put(ctx, req.(*PutRequest))
}
return interceptor(ctx, in, info, handler)
}
var _KV_serviceDesc = grpc.ServiceDesc{
ServiceName: "proto.KV",
HandlerType: (*KVServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Get",
Handler: _KV_Get_Handler,
},
{
MethodName: "Put",
Handler: _KV_Put_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "kv.proto",
}
func init() { proto1.RegisterFile("kv.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 162 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xc8, 0x2e, 0xd3, 0x2b,
0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x53, 0x4a, 0x72, 0x5c, 0x5c, 0xee, 0xa9, 0x25, 0x41,
0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x02, 0x5c, 0xcc, 0xd9, 0xa9, 0x95, 0x12, 0x8c, 0x0a,
0x8c, 0x1a, 0x9c, 0x41, 0x20, 0xa6, 0x92, 0x32, 0x17, 0x37, 0x58, 0xbe, 0xb8, 0x20, 0x3f, 0xaf,
0x38, 0x55, 0x48, 0x84, 0x8b, 0xb5, 0x2c, 0x31, 0xa7, 0x34, 0x15, 0xac, 0x84, 0x27, 0x08, 0xc2,
0x51, 0x32, 0xe1, 0xe2, 0x0a, 0x28, 0xc5, 0x6d, 0x08, 0x42, 0x17, 0x13, 0xb2, 0x2e, 0x76, 0x2e,
0x56, 0xd7, 0xdc, 0x82, 0x92, 0x4a, 0xa3, 0x28, 0x2e, 0x26, 0xef, 0x30, 0x21, 0x1d, 0x2e, 0x66,
0xf7, 0xd4, 0x12, 0x21, 0x41, 0x88, 0xfb, 0xf4, 0x10, 0xae, 0x92, 0x12, 0x42, 0x16, 0x82, 0x3a,
0x44, 0x8d, 0x8b, 0x39, 0xa0, 0x14, 0xa1, 0x1a, 0x61, 0xbd, 0x14, 0x0f, 0x54, 0x08, 0x6c, 0x76,
0x12, 0x1b, 0x98, 0x63, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x06, 0x32, 0x05, 0x89, 0xf9, 0x00,
0x00, 0x00,
}
-22
View File
@@ -1,22 +0,0 @@
syntax = "proto3";
package proto;
message GetRequest {
string key = 1;
}
message GetResponse {
bytes value = 1;
}
message PutRequest {
string key = 1;
bytes value = 2;
}
message Empty {}
service KV {
rpc Get(GetRequest) returns (GetResponse);
rpc Put(PutRequest) returns (Empty);
}
-47
View File
@@ -1,47 +0,0 @@
package shared
import (
"github.com/hashicorp/go-plugin/examples/grpc/proto"
"golang.org/x/net/context"
)
// GRPCClient is an implementation of KV that talks over RPC.
type GRPCClient struct{ client proto.KVClient }
func (m *GRPCClient) Put(key string, value []byte) error {
_, err := m.client.Put(context.Background(), &proto.PutRequest{
Key: key,
Value: value,
})
return err
}
func (m *GRPCClient) Get(key string) ([]byte, error) {
resp, err := m.client.Get(context.Background(), &proto.GetRequest{
Key: key,
})
if err != nil {
return nil, err
}
return resp.Value, nil
}
// Here is the gRPC server that GRPCClient talks to.
type GRPCServer struct {
// This is the real implementation
Impl KV
}
func (m *GRPCServer) Put(
ctx context.Context,
req *proto.PutRequest) (*proto.Empty, error) {
return &proto.Empty{}, m.Impl.Put(req.Key, req.Value)
}
func (m *GRPCServer) Get(
ctx context.Context,
req *proto.GetRequest) (*proto.GetResponse, error) {
v, err := m.Impl.Get(req.Key)
return &proto.GetResponse{Value: v}, err
}
@@ -1,55 +0,0 @@
// Package shared contains shared data between the host and plugins.
package shared
import (
"net/rpc"
"google.golang.org/grpc"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-plugin/examples/grpc/proto"
)
// Handshake is a common handshake that is shared by plugin and host.
var Handshake = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "BASIC_PLUGIN",
MagicCookieValue: "hello",
}
// PluginMap is the map of plugins we can dispense.
var PluginMap = map[string]plugin.Plugin{
"kv": &KVPlugin{},
}
// KV is the interface that we're exposing as a plugin.
type KV interface {
Put(key string, value []byte) error
Get(key string) ([]byte, error)
}
// This is the implementation of plugin.Plugin so we can serve/consume this.
// We also implement GRPCPlugin so that this plugin can be served over
// gRPC.
type KVPlugin struct {
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl KV
}
func (p *KVPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
return &RPCServer{Impl: p.Impl}, nil
}
func (*KVPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &RPCClient{client: c}, nil
}
func (p *KVPlugin) GRPCServer(s *grpc.Server) error {
proto.RegisterKVServer(s, &GRPCServer{Impl: p.Impl})
return nil
}
func (p *KVPlugin) GRPCClient(c *grpc.ClientConn) (interface{}, error) {
return &GRPCClient{client: proto.NewKVClient(c)}, nil
}
-42
View File
@@ -1,42 +0,0 @@
package shared
import (
"net/rpc"
)
// RPCClient is an implementation of KV that talks over RPC.
type RPCClient struct{ client *rpc.Client }
func (m *RPCClient) Put(key string, value []byte) error {
// We don't expect a response, so we can just use interface{}
var resp interface{}
// The args are just going to be a map. A struct could be better.
return m.client.Call("Plugin.Put", map[string]interface{}{
"key": key,
"value": value,
}, &resp)
}
func (m *RPCClient) Get(key string) ([]byte, error) {
var resp []byte
err := m.client.Call("Plugin.Get", key, &resp)
return resp, err
}
// Here is the RPC server that RPCClient talks to, conforming to
// the requirements of net/rpc
type RPCServer struct {
// This is the real implementation
Impl KV
}
func (m *RPCServer) Put(args map[string]interface{}, resp *interface{}) error {
return m.Impl.Put(args["key"].(string), args["value"].([]byte))
}
func (m *RPCServer) Get(key string, resp *[]byte) error {
v, err := m.Impl.Get(key)
*resp = v
return err
}
-3
View File
@@ -1,3 +0,0 @@
package grpctest
//go:generate protoc -I ./ ./test.proto --go_out=plugins=grpc:.
-329
View File
@@ -1,329 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: test.proto
/*
Package grpctest is a generated protocol buffer package.
It is generated from these files:
test.proto
It has these top-level messages:
TestRequest
TestResponse
PrintKVRequest
PrintKVResponse
*/
package grpctest
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type TestRequest struct {
Input int32 `protobuf:"varint,1,opt,name=Input" json:"Input,omitempty"`
}
func (m *TestRequest) Reset() { *m = TestRequest{} }
func (m *TestRequest) String() string { return proto.CompactTextString(m) }
func (*TestRequest) ProtoMessage() {}
func (*TestRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *TestRequest) GetInput() int32 {
if m != nil {
return m.Input
}
return 0
}
type TestResponse struct {
Output int32 `protobuf:"varint,2,opt,name=Output" json:"Output,omitempty"`
}
func (m *TestResponse) Reset() { *m = TestResponse{} }
func (m *TestResponse) String() string { return proto.CompactTextString(m) }
func (*TestResponse) ProtoMessage() {}
func (*TestResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *TestResponse) GetOutput() int32 {
if m != nil {
return m.Output
}
return 0
}
type PrintKVRequest struct {
Key string `protobuf:"bytes,1,opt,name=Key" json:"Key,omitempty"`
// Types that are valid to be assigned to Value:
// *PrintKVRequest_ValueString
// *PrintKVRequest_ValueInt
Value isPrintKVRequest_Value `protobuf_oneof:"Value"`
}
func (m *PrintKVRequest) Reset() { *m = PrintKVRequest{} }
func (m *PrintKVRequest) String() string { return proto.CompactTextString(m) }
func (*PrintKVRequest) ProtoMessage() {}
func (*PrintKVRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
type isPrintKVRequest_Value interface {
isPrintKVRequest_Value()
}
type PrintKVRequest_ValueString struct {
ValueString string `protobuf:"bytes,2,opt,name=ValueString,oneof"`
}
type PrintKVRequest_ValueInt struct {
ValueInt int32 `protobuf:"varint,3,opt,name=ValueInt,oneof"`
}
func (*PrintKVRequest_ValueString) isPrintKVRequest_Value() {}
func (*PrintKVRequest_ValueInt) isPrintKVRequest_Value() {}
func (m *PrintKVRequest) GetValue() isPrintKVRequest_Value {
if m != nil {
return m.Value
}
return nil
}
func (m *PrintKVRequest) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *PrintKVRequest) GetValueString() string {
if x, ok := m.GetValue().(*PrintKVRequest_ValueString); ok {
return x.ValueString
}
return ""
}
func (m *PrintKVRequest) GetValueInt() int32 {
if x, ok := m.GetValue().(*PrintKVRequest_ValueInt); ok {
return x.ValueInt
}
return 0
}
// XXX_OneofFuncs is for the internal use of the proto package.
func (*PrintKVRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
return _PrintKVRequest_OneofMarshaler, _PrintKVRequest_OneofUnmarshaler, _PrintKVRequest_OneofSizer, []interface{}{
(*PrintKVRequest_ValueString)(nil),
(*PrintKVRequest_ValueInt)(nil),
}
}
func _PrintKVRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
m := msg.(*PrintKVRequest)
// Value
switch x := m.Value.(type) {
case *PrintKVRequest_ValueString:
b.EncodeVarint(2<<3 | proto.WireBytes)
b.EncodeStringBytes(x.ValueString)
case *PrintKVRequest_ValueInt:
b.EncodeVarint(3<<3 | proto.WireVarint)
b.EncodeVarint(uint64(x.ValueInt))
case nil:
default:
return fmt.Errorf("PrintKVRequest.Value has unexpected type %T", x)
}
return nil
}
func _PrintKVRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
m := msg.(*PrintKVRequest)
switch tag {
case 2: // Value.ValueString
if wire != proto.WireBytes {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeStringBytes()
m.Value = &PrintKVRequest_ValueString{x}
return true, err
case 3: // Value.ValueInt
if wire != proto.WireVarint {
return true, proto.ErrInternalBadWireType
}
x, err := b.DecodeVarint()
m.Value = &PrintKVRequest_ValueInt{int32(x)}
return true, err
default:
return false, nil
}
}
func _PrintKVRequest_OneofSizer(msg proto.Message) (n int) {
m := msg.(*PrintKVRequest)
// Value
switch x := m.Value.(type) {
case *PrintKVRequest_ValueString:
n += proto.SizeVarint(2<<3 | proto.WireBytes)
n += proto.SizeVarint(uint64(len(x.ValueString)))
n += len(x.ValueString)
case *PrintKVRequest_ValueInt:
n += proto.SizeVarint(3<<3 | proto.WireVarint)
n += proto.SizeVarint(uint64(x.ValueInt))
case nil:
default:
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
}
return n
}
type PrintKVResponse struct {
}
func (m *PrintKVResponse) Reset() { *m = PrintKVResponse{} }
func (m *PrintKVResponse) String() string { return proto.CompactTextString(m) }
func (*PrintKVResponse) ProtoMessage() {}
func (*PrintKVResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func init() {
proto.RegisterType((*TestRequest)(nil), "grpctest.TestRequest")
proto.RegisterType((*TestResponse)(nil), "grpctest.TestResponse")
proto.RegisterType((*PrintKVRequest)(nil), "grpctest.PrintKVRequest")
proto.RegisterType((*PrintKVResponse)(nil), "grpctest.PrintKVResponse")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for Test service
type TestClient interface {
Double(ctx context.Context, in *TestRequest, opts ...grpc.CallOption) (*TestResponse, error)
PrintKV(ctx context.Context, in *PrintKVRequest, opts ...grpc.CallOption) (*PrintKVResponse, error)
}
type testClient struct {
cc *grpc.ClientConn
}
func NewTestClient(cc *grpc.ClientConn) TestClient {
return &testClient{cc}
}
func (c *testClient) Double(ctx context.Context, in *TestRequest, opts ...grpc.CallOption) (*TestResponse, error) {
out := new(TestResponse)
err := grpc.Invoke(ctx, "/grpctest.Test/Double", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *testClient) PrintKV(ctx context.Context, in *PrintKVRequest, opts ...grpc.CallOption) (*PrintKVResponse, error) {
out := new(PrintKVResponse)
err := grpc.Invoke(ctx, "/grpctest.Test/PrintKV", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Test service
type TestServer interface {
Double(context.Context, *TestRequest) (*TestResponse, error)
PrintKV(context.Context, *PrintKVRequest) (*PrintKVResponse, error)
}
func RegisterTestServer(s *grpc.Server, srv TestServer) {
s.RegisterService(&_Test_serviceDesc, srv)
}
func _Test_Double_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(TestRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TestServer).Double(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpctest.Test/Double",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TestServer).Double(ctx, req.(*TestRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Test_PrintKV_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PrintKVRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TestServer).PrintKV(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/grpctest.Test/PrintKV",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TestServer).PrintKV(ctx, req.(*PrintKVRequest))
}
return interceptor(ctx, in, info, handler)
}
var _Test_serviceDesc = grpc.ServiceDesc{
ServiceName: "grpctest.Test",
HandlerType: (*TestServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Double",
Handler: _Test_Double_Handler,
},
{
MethodName: "PrintKV",
Handler: _Test_PrintKV_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "test.proto",
}
func init() { proto.RegisterFile("test.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 240 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2a, 0x49, 0x2d, 0x2e,
0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x48, 0x2f, 0x2a, 0x48, 0x06, 0xf1, 0x95, 0x94,
0xb9, 0xb8, 0x43, 0x52, 0x8b, 0x4b, 0x82, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x44, 0xb8,
0x58, 0x3d, 0xf3, 0x0a, 0x4a, 0x4b, 0x24, 0x18, 0x15, 0x18, 0x35, 0x58, 0x83, 0x20, 0x1c, 0x25,
0x35, 0x2e, 0x1e, 0x88, 0xa2, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x31, 0x2e, 0x36, 0xff,
0xd2, 0x12, 0x90, 0x32, 0x26, 0xb0, 0x32, 0x28, 0x4f, 0x29, 0x97, 0x8b, 0x2f, 0xa0, 0x28, 0x33,
0xaf, 0xc4, 0x3b, 0x0c, 0x66, 0x9e, 0x00, 0x17, 0xb3, 0x77, 0x6a, 0x25, 0xd8, 0x34, 0xce, 0x20,
0x10, 0x53, 0x48, 0x89, 0x8b, 0x3b, 0x2c, 0x31, 0xa7, 0x34, 0x35, 0xb8, 0xa4, 0x28, 0x33, 0x2f,
0x1d, 0x6c, 0x00, 0xa7, 0x07, 0x43, 0x10, 0xb2, 0xa0, 0x90, 0x0c, 0x17, 0x07, 0x98, 0xeb, 0x99,
0x57, 0x22, 0xc1, 0x0c, 0xb2, 0xc1, 0x83, 0x21, 0x08, 0x2e, 0xe2, 0xc4, 0xce, 0xc5, 0x0a, 0x66,
0x2b, 0x09, 0x72, 0xf1, 0xc3, 0xad, 0x83, 0xb8, 0xcc, 0xa8, 0x99, 0x91, 0x8b, 0x05, 0xe4, 0x54,
0x21, 0x4b, 0x2e, 0x36, 0x97, 0xfc, 0xd2, 0xa4, 0x9c, 0x54, 0x21, 0x51, 0x3d, 0x98, 0x67, 0xf5,
0x90, 0x7c, 0x2a, 0x25, 0x86, 0x2e, 0x0c, 0x31, 0x41, 0x89, 0x41, 0xc8, 0x81, 0x8b, 0x1d, 0x6a,
0xac, 0x90, 0x04, 0x42, 0x11, 0xaa, 0xc7, 0xa4, 0x24, 0xb1, 0xc8, 0xc0, 0x4c, 0x48, 0x62, 0x03,
0x87, 0xb2, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x34, 0x25, 0xf9, 0xb5, 0x73, 0x01, 0x00, 0x00,
}
-27
View File
@@ -1,27 +0,0 @@
syntax = "proto3";
package grpctest;
message TestRequest {
int32 Input = 1;
}
message TestResponse {
int32 Output = 2;
}
message PrintKVRequest {
string Key = 1;
oneof Value {
string ValueString = 2;
int32 ValueInt = 3;
}
}
message PrintKVResponse {
}
service Test {
rpc Double(TestRequest) returns (TestResponse) {}
rpc PrintKV(PrintKVRequest) returns (PrintKVResponse) {}
}