英文:
Cannot import proto file in Golang project
问题
import "filter.proto";
导入"filter.proto";未找到或存在错误的导入"filter.proto"。
我无法做到这一点。我不知道如何将--protoc_path添加到我的目录中。它的应用程序将在Docker中运行。
我使用的是VS Code。
这是我的另一个文件(filter.proto):
syntax = "proto3";
package common.filter.v1;
option go_package = "github.com/../../server/gen/go/common/filter/v1;pb_common_filter";
message Pagination {
uint64 limit = 1;
uint64 offset = 2;
}
我的目录结构如下:
proto
- common
- filter
- v1
- filter.proto
- service
- products
- v1
- service.proto
它们都在服务器文件夹中。
我尝试过更改导入中的路径,但没有任何效果。
英文:
import "filter.proto"; Import "filter.proto" was not found or had errors.
I cannot to do this. I dont relize how to add --protoc_path to my dir. Its app will be in docker.
i use vs code
its my another file (filter.proto):
syntax = "proto3";
package common.filter.v1;
option go_package = "github.com/../../server/gen/go/common/filter/v1;pb_common_filter";
message Pagination { uint64 limit = 1; uint64 offset = 2; }
my dirs:
proto
-common
-filter
-v1
filter.proto
-service
-products
-v1
-service.proto
its all in the folder (server)
i tried rename path in import, but i nothing
答案1
得分: 1
你无法导入一个protobuf定义,因为它不是一个有效的Go包。你需要将protobuf编译成Go代码。可以搜索"protobuf转换为golang结构体"。这个Stack Overflow的问题有一个相当不错的答案:https://stackoverflow.com/questions/75705541/convert-protobuf-to-struct-in-golang。当然,你还应该阅读官方的protobuf文档。我建议从教程开始:https://protobuf.dev/getting-started/gotutorial/。
英文:
You can't import a protobuf definition because it isn't a valid Go package. You have to compile the protobuf into Go code. Google "protobuf to golang struct". This SO question has a reasonably good answer: https://stackoverflow.com/questions/75705541/convert-protobuf-to-struct-in-golang. Obviously you should also read the official protobuf documentation. I recommend starting with the tutorial: https://protobuf.dev/getting-started/gotutorial/.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论