从不同的文件导入原始
我将所有原始文件都保存在一个文件夹中。概述:
protos
|
|__auth
|
|__some_other
内部auth
目录I有auth_service.proto
user.proto
等。
syntax="proto3";
package auth;
import "auth/user.proto"; // Import "auth/user.proto" was not found or had errors.
message SomeMessage {
User user = 1; // user is not defined
}
syntax="proto3";
package auth;
message User{}
I maintain all my proto files in one folder. An overview:
protos
|
|__auth
|
|__some_other
Inside auth
directory I have auth_service.proto
user.proto
etc.
But I am having issues with importing definitions form user.proto
In auth_service.proto
:
syntax="proto3";
package auth;
import "auth/user.proto"; // Import "auth/user.proto" was not found or had errors.
message SomeMessage {
User user = 1; // user is not defined
}
user.proto has the same package name:
syntax="proto3";
package auth;
message User{}
Protoc version: libprotoc : 3.19.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能很棘手。
考虑一下它的一种方法是,您需要确定导入路径的根,然后原始导入是相对于它的。
假设
$ {PWD}
是Protos
的父。示例#1:
如果您使用
$ {pwd}
作为proto_path
:导入应为
导入“ protos/auth/auth/user.proto”;
示例#2:
如果您使用
Protos
作为proto_path
:导入应为
导入“ auth/user.proto”;
。settings.json
:This can be tricky.
One way to think about it is that you need to determine the root of the import path and then proto imports are relative to it.
Assuming
${PWD}
is the parent ofprotos
.Example #1:
If you use
${PWD}
as theproto_path
:Then the import should be
import "protos/auth/user.proto";
Example #2:
If you use
protos
as theproto_path
:Then the import should be
import "auth/user.proto";
.settings.json
: