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;
}
}
THE END