分享一个合并 protobuf 的小工具

2023-05-11 12:14:24 +08:00
 joesonw

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

}

希望能帮助到有需要的人

1554 次点击
所在节点    分享创造
1 条回复
taofoo
2023-05-14 20:26:52 +08:00
这两个我弄 swagger 的 Openapi.yaml 文件做过类似的 哈哈

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/939156

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX