protoc-gen-validate import文件导入问题

问题:

proto 

syntax = "proto3";
option go_package = ".;proto";
import "validate.proto";

service Greeter{
  rpc SayHello(Person) returns (Person);
}

message Person {
  uint64 id = 1 [(validate.rules).uint64.gt = 999];

  string email = 2 [(validate.rules).string.email = true];

  string name = 3 [(validate.rules).string = {
    pattern:   "[\u4e00-\u9fa5]",
    max_bytes: 30,
  }];

  Location home = 4 [(validate.rules).message.required = true];

  message Location {
    double lat = 1 [(validate.rules).double = {gte: -90,  lte: 90}];
    double lng = 2 [(validate.rules).double = {gte: -180, lte: 180}];
  }
}

proto文件生成对应go语言文件

 protoc -I ./  --go_out=. --validate_out="lang=go:." helloworld.proto

出现问题报错

google/protobuf/descriptor.proto: File not found.
google/protobuf/duration.proto: File not found.
google/protobuf/timestamp.proto: File not found.
validate.proto:7:1: Import "google/protobuf/descriptor.proto" was not found or had errors.
validate.proto:8:1: Import "google/protobuf/duration.proto" was not found or had errors.
validate.proto:9:1: Import "google/protobuf/timestamp.proto" was not found or had errors.
validate.proto:798:12: "google.protobuf.Duration" is not defined.
validate.proto:802:12: "google.protobuf.Duration" is not defined.
validate.proto:806:12: "google.protobuf.Duration" is not defined.
validate.proto:810:12: "google.protobuf.Duration" is not defined.
validate.proto:814:12: "google.protobuf.Duration" is not defined.
validate.proto:818:12: "google.protobuf.Duration" is not defined.
validate.proto:822:12: "google.protobuf.Duration" is not defined.
validate.proto:832:12: "google.protobuf.Timestamp" is not defined.
validate.proto:836:12: "google.protobuf.Timestamp" is not defined.
validate.proto:840:12: "google.protobuf.Timestamp" is not defined.
validate.proto:844:12: "google.protobuf.Timestamp" is not defined.
validate.proto:848:12: "google.protobuf.Timestamp" is not defined.
validate.proto:861:12: "google.protobuf.Duration" is not defined.
validate.proto:12:8: "google.protobuf.MessageOptions" is not defined.
validate.proto: "google.protobuf.MessageOptions" is not defined.
validate.proto:21:8: "google.protobuf.OneofOptions" is not defined.
validate.proto:28:8: "google.protobuf.FieldOptions" is not defined.
helloworld.proto:3:1: Import "validate.proto" was not found or had errors.

先去github上面下载需要的文件

Release Protocol Buffers v23.1 · protocolbuffers/protobuf · GitHub 

把需要的google文件 放入自己go_path的src目录下面

 

 

指定路径

protoc -I ./ -I "D:\Go\src" --go_out=. --validate_out="lang=go:." helloworld.proto

参考文章

Windows下protoc-gen-validate的安装使用_lwb拾光的博客-CSDN博客

gRPC集成protoc-gen-validate_.番茄炒蛋的博客-CSDN博客

https://www.cnblogs.com/yisany/p/14875488.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值