【问题标题】:How to import gRPC empty and Google api annotations proto如何导入 gRPC empty 和 Google api annotations proto
【发布时间】:2017-09-04 21:47:36
【问题描述】:

我正在尝试使用 Google Cloud Endpoints 制作一个基于 gRPC 的 API,它可以 transcode incoming REST requests。我正在关注their example code,但我没有任何关于如何使用 annotation.proto 或 empty.proto 正确导入和编译的文档。

谢谢!

【问题讨论】:

    标签: google-cloud-platform protocol-buffers google-cloud-endpoints grpc protoc


    【解决方案1】:

    $GOPATH/pkg/mod 下安装时,使用go list -m -f '{{.Dir}}' 有助于更好地解决go mod 依赖关系。

    grpc_ecosystem_path=`go list -m -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway`
    
    protoc \
        --proto_path="$grpc_ecosystem_path/third_party/googleapis" \
    # ...
    

    【讨论】:

      【解决方案2】:

      这可能不是一个好主意。 您可以将google/api/annotations.protogoogle/api/http.proto 复制到本地项目中,并在运行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
      

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

      【讨论】:

      • 这对我不起作用。我有 grpcio 和 grpcio-tools。在添加这两个文件时,我收到错误“google.protobuf.MethodOptions”未定义(在 annotations.proto 中)。如何克服这个问题?
      【解决方案3】:

      empty.proto 和 annotation.proto 默认不包括在内,所以你需要带一个副本。具体来说,您可以在项目的目录中复制它们,或者在现有项目中引用它们(例如 Protobuf git repo)。

      引用 grpc-ecosystem/grpc-gateway 使用的副本可能是个好主意,因为他们将来可能想移动它。

      【讨论】:

        【解决方案4】:

        我不明白这是 grpc-gateway 的一部分。 following the docs我跑了

        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
        

        并编译成功。

        【讨论】:

          猜你喜欢
          • 2018-06-04
          • 1970-01-01
          • 1970-01-01
          • 2019-03-18
          • 2017-11-12
          • 2021-04-17
          • 1970-01-01
          • 1970-01-01
          • 2017-03-16
          相关资源
          最近更新 更多