19

I am trying to use Google Cloud Endpoints to make a gRPC based api that can transcode incoming REST requests. I am following their example code but I can not any documentation on how to properly import and compile with the annotation.proto or the empty.proto.

Thank you!

Arjun Yelamanchili
  • 577
  • 1
  • 3
  • 16

4 Answers4

14

I didn't understand that this was part of grpc-gateway. By following the docs I ran

protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. *.proto

and compiled successfully.

Arjun Yelamanchili
  • 577
  • 1
  • 3
  • 16
8

it may not be a good idea. you can copy google/api/annotations.proto and google/api/http.proto into your local project and import them when run python -m

mkdir -p google/api    
curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/annotations.proto > google/api/annotations.proto     
curl https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/http.proto > google/api/http.proto

python -m grpc_tools.protoc google/api/http.proto google/api/annotations.proto -I. --python_out=. --grpc_python_out=. your_proto.proto

refurl: https://cloud.google.com/solutions/exposing-grpc-services-using-cloud-endpoints-pt1

gaozhidf
  • 2,621
  • 1
  • 22
  • 17
  • It's not working for me. I have grpcio and grpcio-tools. On adding the two files, I get the error "google.protobuf.MethodOptions" is not defined (in annotations.proto). How to get past this? – Shivansh Jagga Apr 28 '21 at 15:41
5

The empty.proto and annotation.proto are not included by default, so you'll need to bring in a copy. Specifically you can make a copy of them in a directory in your project, or reference them in an existing project (like the Protobuf git repo, for instance).

It is probably a good idea to NOT reference the copy that grpc-ecosystem/grpc-gateway uses, because they may want to move it around in the future.

Carl Mastrangelo
  • 5,970
  • 1
  • 28
  • 37
0

Using go list -m -f '{{.Dir}}' helps better resolve go mod dependencies when installed under $GOPATH/pkg/mod.

grpc_ecosystem_path=`go list -m -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway`

protoc \
    --proto_path="$grpc_ecosystem_path/third_party/googleapis" \
# ...
syvex
  • 7,518
  • 9
  • 43
  • 47