How to import gRPC empty and Google api annotations proto
Asked Answered
S

4

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!

Statius answered 9/4, 2017 at 23:58 Comment(0)
S
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.

Statius answered 10/4, 2017 at 15:33 Comment(0)
C
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

Cabriolet answered 7/11, 2018 at 4:7 Comment(1)
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?Fairhaired
M
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.

Mccall answered 18/4, 2017 at 23:2 Comment(0)
A
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" \
# ...
Add answered 3/11, 2021 at 23:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.