• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..17-Feb-2020-

_grpc_test/H17-Feb-2020-531421

README.mdH A D17-Feb-20202.1 KiB5542

client.goH A D17-Feb-20203.9 KiB14197

client_test.goH A D17-Feb-20201.2 KiB6249

doc.goH A D17-Feb-202068 31

encode_decode.goH A D17-Feb-20201.5 KiB308

request_response_funcs.goH A D17-Feb-20202.8 KiB8246

server.goH A D17-Feb-20204.8 KiB169114

README.md

1# grpc
2
3[gRPC](http://www.grpc.io/) is an excellent, modern IDL and transport for
4microservices. If you're starting a greenfield project, go-kit strongly
5recommends gRPC as your default transport.
6
7One important note is that while gRPC supports streaming requests and replies,
8go-kit does not. You can still use streams in your service, but their
9implementation will not be able to take advantage of many go-kit features like middleware.
10
11Using gRPC and go-kit together is very simple.
12
13First, define your service using protobuf3. This is explained
14[in gRPC documentation](http://www.grpc.io/docs/#defining-a-service).
15See
16[add.proto](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/pb/add.proto)
17for an example. Make sure the proto definition matches your service's go-kit
18(interface) definition.
19
20Next, get the protoc compiler.
21
22You can download pre-compiled binaries from the
23[protobuf release page](https://github.com/google/protobuf/releases).
24You will unzip a folder called `protoc3` with a subdirectory `bin` containing
25an executable. Move that executable somewhere in your `$PATH` and you're good
26to go!
27
28It can also be built from source.
29
30```sh
31brew install autoconf automake libtool
32git clone https://github.com/google/protobuf
33cd protobuf
34./autogen.sh ; ./configure ; make ; make install
35```
36
37Then, compile your service definition, from .proto to .go.
38
39```sh
40protoc add.proto --go_out=plugins=grpc:.
41```
42
43Finally, write a tiny binding from your service definition to the gRPC
44definition. It's a simple conversion from one domain to another.
45See
46[grpc_binding.go](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/grpc_binding.go)
47for an example.
48
49That's it!
50The gRPC binding can be bound to a listener and serve normal gRPC requests.
51And within your service, you can use standard go-kit components and idioms.
52See [addsvc](https://github.com/go-kit/kit/tree/master/examples/addsvc) for
53a complete working example with gRPC support. And remember: go-kit services
54can support multiple transports simultaneously.
55