亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在不復制谷歌文件的情況下制作工作協議?

如何在不復制谷歌文件的情況下制作工作協議?

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 關注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號