3 回答
TA贡献1818条经验 获得超11个赞
您尝试下载的原型来自此模块
env GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
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
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它。
- 3 回答
- 0 关注
- 115 浏览
添加回答
举报
