Unable to figure out missing protoc command from udemy course

209 views Asked by At

Problem:

I have been coding along to a Golang microservices course on Udemy the last week or so and have encountered a problem.

Basically the instructor has introduced us to Go-Micro and RPC by writing a .proto file. Now I have a bit of experience with GRPC, but none with Go-Micro. The problem is that the instructor doesn't show the actual protoc command and eventual flags, but just brushes over it. I assumed it would be a trivial command, but after running protoc greeter.proto go_out=. I am missing the client snippets..

Expected:

That the pb.go file would look the same as the instructor's, with client side and server snippets in the pb.go file.

Actual:

Missing client snippets.

Command run:

protoc greeter.proto go_out=.

Code:

.proto file:

syntax = "proto3";

service Greeter { 
    rpc Hello(HelloRequest) returns (HelloResponse) {}
}

message HelloRequest {
    string name = 1;
}

message HelloResponse {
    string greeting = 2;
}
3

There are 3 answers

2
Bert Verhees On

I use this command:

protoc --proto_path=$GOPATH/src:. --micro_out=. --go_out=plugins=grpc:. *.proto 

from the directory where the proto-files are. It generates as well service as client code. I found this command in one of the many examples from the go-micro github repository and the go-micro web-site.

This is, however, for use with grpc, but the idea is alright.

0
Black_Dreams On

Hope this helps :

First one is to generate the proto file and 2nd one is for reverse proxy

In this filename.proto :- filename is your file name

# Generate proto
protoc -I/usr/local/include -I.  -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=google/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. filename.proto

#Reverse Proxy For REST
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. filename.proto
0
Aj Tech Developer On

Here is an example of protoc command:

protoc proto/employee.proto --go_out=plugins=grpc:.

A new file employee.pb.go will be generated in the proto folder.

If you are looking for a simple example of a Golang gRPC Microservice, please check the post below which has all the steps explained with working code in GitHub: https://softwaredevelopercentral.blogspot.com/2021/03/golang-grpc-microservice.html