You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
696 B

  1. syntax = "proto3"; //指定版本信息,不指定会报错
  2. package pb; //后期生成go文件的包名
  3. //message为关键字,作用为定义一种消息类型
  4. message Person {
  5. string name = 1; //姓名
  6. int32 age = 2; //年龄
  7. repeated string emails = 3; //电子邮件(repeated表示字段允许重复)
  8. repeated PhoneNumber phones = 4; //手机号
  9. }
  10. //enum为关键字,作用为定义一种枚举类型
  11. enum PhoneType {
  12. MOBILE = 0;
  13. HOME = 1;
  14. WORK = 2;
  15. }
  16. //message为关键字,作用为定义一种消息类型可以被另外的消息类型嵌套使用
  17. message PhoneNumber {
  18. string number = 1;
  19. PhoneType type = 2;
  20. }