首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在不复制google文件的情况下在go中进行工作协议?

如何在不复制google文件的情况下在go中进行工作协议?
EN

Stack Overflow用户
提问于 2020-08-28 02:02:23
回答 3查看 708关注 0票数 0

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

但仍然没有办法

EN

回答 3

Stack Overflow用户

发布于 2020-08-31 16:39:29

您尝试下载的protos来自此模块

代码语言:javascript
复制
env GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
票数 1
EN

Stack Overflow用户

发布于 2020-08-28 04:01:25

看看这个(摘自Dockerfile):

代码语言:javascript
复制
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得到protocprotoc-gen-go-protoc-gen-grpc-gateway

第二个RUN使用go list识别已安装的grpc-gateway模块,并将protoc指向该模块。

票数 0
EN

Stack Overflow用户

发布于 2021-11-07 19:39:14

我的解决方案是:

代码语言:javascript
复制
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将模块下载到本地之前

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63621788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档