为了账号安全,请及时绑定邮箱和手机立即绑定

如何在不复制谷歌文件的情况下制作工作协议?

如何在不复制谷歌文件的情况下制作工作协议?

Go
呼如林 2022-06-27 14:58:25
我正在尝试使用 https://github.com/grpc-ecosystem/grpc-gateway但是当我尝试运行时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,paths=source_relative:./ example/example.proto错误 src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis:警告:目录不存在。为了解决这个问题,我手动带来了必要的文件,但我觉得这是不必要的,有一种方法可以让它自动化,我之前运行过 go get -u github.com/grpc-ecosystem/grpc-gateway/但还是没办法
查看完整描述

3 回答

?
慕尼黑8549860

TA贡献1818条经验 获得超11个赞

您尝试下载的原型来自此模块

env GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2



查看完整回答
反对 回复 2022-06-27
?
四季花海

TA贡献1811条经验 获得超5个赞

我的解决方案是:

protoc --go_out=./ --go-grpc_out=./ -I$(go list -f '{{ .Dir }}' -m github.com/example/example) example/example.proto

它在当前目录中生成 .pb.go 和 _grpc.pb.go 文件

github.com/example/example

go 想要交互的模块名称

示例/example.proto

原始文件/文件的 repo url 的相对路径

同样在您应该通过以下方式在本地下载模块之前go get github.com/example/example


查看完整回答
反对 回复 2022-06-27
?
慕的地8271018

TA贡献1796条经验 获得超4个赞

看看这个(从 a 中提取Dockerfile):


ARG VERS="3.13.0"

ARG ARCH="linux-x86_64"

RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v${VERS}/protoc-${VERS}-${ARCH}.zip --output-document=./protoc-${VERS}-${ARCH}.zip && \

    apt update && apt install -y unzip && \

    unzip -o protoc-${VERS}-${ARCH}.zip -d protoc-${VERS}-${ARCH} && \

    mv protoc-${VERS}-${ARCH}/bin/* /usr/local/bin && \

    mv protoc-${VERS}-${ARCH}/include/* /usr/local/include && \

    go get -u github.com/golang/protobuf/protoc-gen-go && \

    go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway


ARG REPO="..."

ARG MODULE="github.com/${REPO}"


# Generates the Golang protobuf files

# NB Uses `go list` to determine the correct Modules directory for the package (!) containing Google APIs protos

RUN protoc \

    --proto_path=. \

    --proto_path=$(go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis \

    --go_out=plugins=grpc,module=${MODULE}:. \

    ./protos/*.proto

在构建使用 gRPC 网关的基于 gRPC 的解决方案时,我经常使用此代码段。


第一个RUN得到protoc和protoc-gen-go。-protoc-gen-grpc-gateway


第二个RUN用于go list识别已安装的grpc-gateway模块并指向protoc它。


查看完整回答
反对 回复 2022-06-27
  • 3 回答
  • 0 关注
  • 115 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号