https://github.com/joesonw/oneproto
用来把多个 protobuf 合并为一个(如果 package 不同,通过 nested message 来区别命名空间)
用来解决项目大了, protobuf 之间难免会产生相互引用. 但是放在不同的文件中, 维护性又更好, 于是产生了这个小工具
例子
user.proto
syntax = 'proto3';
option go_package = 'generated/proto;pb';
package example.com.users;
import "proto/group.proto";
message User {
string id = 1;
string name = 2;
string email = 3;
string password = 4;
string created_at = 5;
string updated_at = 6;
repeated groups.Group groups = 7;
}
group.proto
syntax = 'proto3';
option go_package = 'generated/proto;pb';
package example.com.groups;
import "proto/user.proto";
message Group {
string name = 1;
repeated users.User users = 2;
}
产生的文件
syntax = 'proto3';
option go_package = 'generated/proto;pb';
package example.com;
message groups {
message Group {
string name = 1;
repeated users.User users = 2;
}
}
message users {
message User {
string id = 1;
string name = 2;
string email = 3;
string password = 4;
string created_at = 5;
string updated_at = 6;
repeated groups.Group groups = 7;
}
}
希望能帮助到有需要的人
1
taofoo 2023-05-14 20:26:52 +08:00
这两个我弄 swagger 的 Openapi.yaml 文件做过类似的 哈哈
|