This project is a small starting point for building a Go client and server that communicate with gRPC. The accompanying gRPC article series explains the contract, generated code, server, and client.
Install the Protocol Buffers compiler using the instructions for your platform. On macOS with Homebrew:
brew install protobufInstall the Go plugins for the Protocol Buffers compiler. The official gRPC-Go quick start lists the same prerequisites.
make installGenerate the client and server bindings, then verify both modules:
make gen
make testRun the server:
make serverIn another terminal, run the client:
make clientThe sample uses plaintext transport only for local development. Configure TLS and authentication before exposing a gRPC service outside your trusted development network.
# Note: since we are not using TLS all the calls are with -plaintext flag
grpcurl -plaintext localhost:8080 list
grpcurl -plaintext localhost:8080 Inventory.GetBookListGenerate Go stubs
make genClean stubs
make clean- VS Code complains about imports?
Known issue with the Proto3 VS Code plugin. Add the following to your settings.json file
"protoc": {
"path": "/path/to/protoc",
"compile_on_save": false,
"options": [
"--proto_path=protos/v3",
"--proto_path=protos/v2",
"--proto_path=${workspaceRoot}/proto",
"--proto_path=${env.GOPATH}/src",
"--java_out=gen/java"
]
}
Run which protoc to find your proto compiler path.
- Auto formatter doesn't work?
brew install clang-formatAdd the following to your settings.json
{
// ...
"editor.formatOnSave": true
// ...
}