我正在尝试使用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
ERROR src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis:警告:目录不存在。
为了解决这个问题,我手动带来了必要的文件,但我觉得这是不必要的,有一种方法可以让它自动执行,我在go get -u github.com/grpc-ecosystem/grpc-gateway/之前运行
但仍然没有办法
发布于 2020-08-31 16:39:29
您尝试下载的protos来自此模块
env GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2发布于 2020-08-28 04:01:25
看看这个(摘自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指向该模块。
发布于 2021-11-07 19:39:14
我的解决方案是:
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
要交互的go模块名称
示例/example.proto
原始文件/文件的存储库url的相对路径
另外,在您应该通过go get github.com/example/example将模块下载到本地之前
https://stackoverflow.com/questions/63621788
复制相似问题