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.