1# Counter Example
2
3This example builds a simple key/counter store CLI where the mechanism
4for storing and retrieving keys is pluggable. However, in this example we don't
5trust the plugin to do the summation work. We use bi-directional plugins to
6call back into the main proccess to do the sum of two numbers. To build this example:
7
8```sh
9# This builds the main CLI
10$ go build -o counter
11
12# This builds the plugin written in Go
13$ go build -o counter-go-grpc ./plugin-go-grpc
14
15# This tells the Counter binary to use the "counter-go-grpc" binary
16$ export COUNTER_PLUGIN="./counter-go-grpc"
17
18# Read and write
19$ ./counter put hello 1
20$ ./counter put hello 1
21
22$ ./counter get hello
232
24```
25
26### Plugin: plugin-go-grpc
27
28This plugin uses gRPC to serve a plugin that is written in Go:
29
30```
31# This builds the plugin written in Go
32$ go build -o counter-go-grpc ./plugin-go-grpc
33
34# This tells the KV binary to use the "kv-go-grpc" binary
35$ export COUNTER_PLUGIN="./counter-go-grpc"
36```
37
38## Updating the Protocol
39
40If you update the protocol buffers file, you can regenerate the file
41using the following command from this directory. You do not need to run
42this if you're just trying the example.
43
44For Go:
45
46```sh
47$ protoc -I proto/ proto/kv.proto --go_out=plugins=grpc:proto/
48```
49