Generating gRPC Client Code and Server Boilerplate
First, go install Protocol Buffers and its Go plugin. Instructions can be found at http://www.grpc.io/docs/quickstart/go.html. This package requires Protobuf3.0+
to work!
Then go get this package
go get http://gopkg.in/marcusljx/grpcgen-go.v0
To create a new service called abc
, set up your project structure as follows:
abc
└── abc
├── doc.go
└── abc.proto
Within doc.go
, you can put all your package Overview
documentation (a la godoc
). At the bottom, add these lines:
//go:generate protoc -I=. --go_out=plugins=grpc:. ./grpctutorial.proto
//go:generate grpcgen-go --gopath-output=github.com/marcusljx/grpctutorial
To generate your code, run go generate
within your INNER abc
directory.
https://godoc.org/gopkg.in/marcusljx/grpcgen-go.v0
This project is still in pre-alpha stage. Do not use in production!
The goal is to be able to create a simple working microservice using the following steps:
- Create a protobuf definition file (
.proto
) - Invoke the protobuf compiler to generate golang interfaces for client and server
- Invoke
grpcgen
to generate Client code, and Server boilerplate code. - Fill in the
logic
within all the Server boilerplate. - Run
go run start_server.go
.
- unit test boilerplate for server methods (using httptest)
- mocking boilerplate (for use either as-is, or with additional logic)