A tool for auto converting go code into gRPC Protobuf file.
- Go 1.5 or later
- gRPC
- gRPC-go
to get gRPC and gRPC-go just type:
$ go get google.golang.org/grpc
$ go get -a github.com/golang/protobuf/protoc-gen-go
simply type these in a go file:
package YourPackageName
//go:generate grpcGen $GOFILE
and then in terminal:
$ go generate
it will generated an example go code for you to modify. once you done the modification, then just type the same command as previous one in the terminal, it will generating an protobuf file and calling gRPC tool to generate an gRPC go code for you. THAT'S IT
There are three important symbol that will be referenced by grpcGen:
- @grpcGen:Message
- @grpcGen:Service
- @grpcGen:SrvName:
It is the Protobuf Message type, gRPC using this Message type for data communication.
In here, you only need to define a go structure but with the message symbol @grpcGen:Message then grpcGen will parsing them into gRPC Message type for you and mark the go structure you defined as commends for letting others to understand our IN, OUT structure looks like!
It is the Protobuf Service type, gRPC using this Service type for defining open interface for letting other programs to call.
In here, you have to define a go function with @grpcGen:Service and @grpcGen:SrvName: symbols.
@grpcGen:SrvName: means the gRPC service name, of course you can defining two functions with the same SrvName, the grpcGen will auto parsing them into same service you named it!