goctl生成protoc报错:Import “google/protobuf/timestamp.proto“ was not found or had errors.

文章讲述了在使用goctlrpc编译protobuf文件user.proto时遇到的错误,因为找不到import的google/protobuf/timestamp.proto。解决方法是通过添加-I参数指定查找导入文件的路径。

Bug

这是我的user.proto 文件,位于D:\Go\workspace\src\Link_Service\app\user\service\user.proto

syntax = "proto3";

package user;
option go_package="./user";
import public "google/protobuf/timestamp.proto";

...


// goctl rpc protoc user.proto --go_out=. --go-grpc_out=. --zrpc_out=.

PS D:\Go\workspace\src\Link_Service\app\user\service>目录下执行goctl rpc protoc user.proto --go_out=. --go-grpc_out=. --zrpc_out=. 报错,报错信息如下:

PS D:\Go\workspace\src\Link_Service\app\user\service> goctl rpc protoc user.proto --go_out=. --go-grpc_out=. --zrpc_out=.
Error: google/protobuf/timestamp.proto: File not found.
      --remote string     The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
                          The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
      --style string      The file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md]
  -v, --verbose           Enable log output
      --zrpc_out string   The zrpc output directory


google/protobuf/timestamp.proto: File not found.
user.proto:5:1: Import "google/protobuf/timestamp.proto" was not found or had errors.
user.proto:115:3: "google.protobuf.Timestamp" is not defined.

原因

user.proto 导入了"google/protobuf/timestamp.proto" 文件,但是执行命令时,user.proto不知道去哪里找timestamp.proto。我们只需要指出去哪里找导入文件即可。

这是我的 timestamp.proto 的路径
在这里插入图片描述

解决

执行goctl命令时加入-I 参数指定去哪里找到导入文件

-I: -I 选项来指定 proto 文件的搜索路径。通常,-I 选项后面会跟着一个目录路径,用于告诉 protoc 命令在哪些目录下搜索 import 语句引入的 proto 文件。
goctl rpc protoc user.proto -I . -I C:\Users\666\AppData\Local\JetBrains\GoLand2022.3\protoeditor --go_out=. --go-grpc_out=. --zrpc_out=.

执行,成功

PS D:\Go\workspace\src\Link_Service\app\user\service> goctl rpc protoc user.proto  -I . -I C:\Users\666\AppData\Local\JetBrains\GoLand2022.3\protoeditor --go_out=. --go-grpc_out=.  --zrpc_out=.
Done.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值