英文:
Grpc Go Generated.pb.go import was not formatted
问题
我从一个项目(https://github.com/maanasasubrahmanyam-sd/customValidation)导入了一个proto文件(validator.proto)到另一个项目(https://github.com/maanasasubrahmanyam-sd/customeValTest/tree/master/interfaces/test_server)中。
go get github.com/maanasasubrahmanyam-sd/customValidation
protoc \
-I. \
-I $GOPATH/src/ \
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0 \
--proto_path=${GOPATH}/src/github.com/google/protobuf/src \
--go_out="plugins=grpc:./generated" \
--validate_out="lang=go:./generated" \
--govalidators_out=. \
./interfaces/test_server/*.proto
正确的导入应该是github.com/maanasasubrahmanyam-sd/customValidation/validator。但是test.pb.go的导入却是**_ "./validator"**,在Goland中显示为红线。
编辑-所有的pb.go文件都显示错误。我怀疑是由于错误的导入导致的。
我在谷歌上搜索了一下,但没有找到相关的信息。有什么建议吗?
英文:
I imported proto file (validator.proto) from one of my project https://github.com/maanasasubrahmanyam-sd/customValidation to another project (test.proto) https://github.com/maanasasubrahmanyam-sd/customeValTest/tree/master/interfaces/test_server
go get github.com/maanasasubrahmanyam-sd/customValidation
protoc \
-I. \
-I $GOPATH/src/ \
--proto_path=${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0 \
--proto_path=${GOPATH}/src/github.com/google/protobuf/src \
--go_out="plugins=grpc:./generated" \
--validate_out="lang=go:./generated" \
--govalidators_out=. \
./interfaces/test_server/*.proto
The correct import should come as github.com/maanasasubrahmanyam-sd/customValidation/validator. But test.pb.go import was coming as _ "./validator" which shows red line in Goland.
EDIT - All pb.go files are showing errors in them. I suspect it is due to bad import.
I google it but did not found any relevant information. Any suggestion experts ?
答案1
得分: 1
你可以通过两种方式来指定 proto 文件的路径:
方式一: 如果你导入的 proto 文件位于本地,你需要将其移动到父目录,然后通过父路径来指定它,例如:
- parentDirectory
-- directory1
--- proto1.proto
-- importDirectory
--- proto2.proto
你可以使用以下命令来构建该文件(proto1.proto):
protoc --proto_path=parentDirectory/directory1 --proto_path=parentDirectory --go-grpc_out=***你的输出路径*** --go_out=***你的输出路径*** parentDirectory/directory1/proto1.proto
- 如果你使用
Goland
,你需要将 parentDirectory 添加到设置中(File | Settings | Languages & Frameworks | Protocol Buffers),然后取消勾选 Configure automatically,并添加你的父路径。
方式二: 如果你的 proto 文件位于 URL 上,你可以在构建命令中添加它,例如:
protoc --proto_path=src \
--go_opt=Mprotos/buzz.proto=example.com/project/protos/fizz \
--go_opt=Mprotos/bar.proto=example.com/project/protos/foo \
protos/buzz.proto protos/bar.proto
英文:
You can address the proto path in two ways,
One: if your import proto file is in your local then you should move it to your parent directory then address it from your parent path like this:
- parentDirectory
-- directory1
--- proto1.proto
-- importDirectory
--- proto2.proto
you can build this file(proto1.proto) with this command :
protoc --proto_path=parentDirectory/directory1 --proto_path=parentDirectory --go-grpc_out=***your output path*** --go_out=***your output path*** parentDirectory/directory1/proto1.proto
- also if you use
Goland
you need to add parentDirectory to your setting(File | Settings | Languages & Frameworks | Protocol Buffers) then uncheck Configure automatically and add your parent path.
Two: If your proto file is in URL: then you can add it to your build command like this:
protoc --proto_path=src \
--go_opt=Mprotos/buzz.proto=example.com/project/protos/fizz \
--go_opt=Mprotos/bar.proto=example.com/project/protos/foo \
protos/buzz.proto protos/bar.proto
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论