使用如下指令将
.proto
檔案轉換為
go
檔案時,發生錯誤。
指令:
protoc --go_out=. *.proto
發生錯誤:
C:\Users\Bestzy\go\src\awesomeProject\pb>protoc --go_out=. myproto.proto
protoc-gen-go: unable to determine Go import path for "myproto.proto"
Please specify either:
• a "go_package" option in the .proto source file, or
• a "M" argument on the command line.
See https://developers.google.com/protocol-buffers/docs/reference/go-generated#package for more information.
--go_out: protoc-gen-go: Plugin failed with status code 1.
解決方法:
在
.proto
檔案中添加如下代碼:
添加之後完整代碼如下:
syntax = "proto3";
package pb;
option go_package ="/"; //添加的代碼
message People{
int32 weight = 1;
}
message Student{
string name = 2;
}
接着使用同樣的指令将檔案導出為
go
檔案,檔案會生成在
.proto
相同的目錄下。