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 關注
- 107 瀏覽
添加回答
舉報