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

我正在尝试使用 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/

但还是没办法


呼如林
浏览 116回答 3
3回答

慕尼黑8549860

您尝试下载的原型来自此模块env GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2

四季花海

我的解决方案是: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/examplego 想要交互的模块名称示例/example.proto原始文件/文件的 repo url 的相对路径同样在您应该通过以下方式在本地下载模块之前go get github.com/example/example

慕的地8271018

看看这个(从 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-gatewayARG 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 protosRUN 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它。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go