当前位置:网站首页>rotoc-gen-go: unable to determine Go import path for **.proto
rotoc-gen-go: unable to determine Go import path for **.proto
2022-07-17 00:08:00 【祥仔先生】
Please specify either:
• a "go_package" option in the .proto source file, or
• a "M" argument on the command line.
在编译proto文件的时候,protoc --go_out=. *.proto,出现上面的命令可能是我们的包名的位置不对,这里我们需要在.proto文件中增加对应的go_package参数来告诉对应的package位置
syntax = "proto2";
package example;
option go_package = "./example";
message Order{
required int32 order_id = 1; //1代表字段顺序
optional int64 num = 2;
optional string timestamp = 3;
optional string basce = 4 [default = 'beijing'];
}proto文件介绍:
Order消息格式有3个字段,在消息中承载的数据分别对应每一个字段。其中每个字段都有一个名字和一种类型。
指定字段类型:在proto协议中,字段的类型包括字符串(string)、整形(int32、int64...)、枚举(enum)等数据类型
分配标识符:在消息字段中,每个字段都有唯一的一个标识符。最小的标识号可以从1开始,最大到536870911。不可以使用其中的[19000-19999]的标识号, Protobuf协议实现中对这些进行了预留。如果非要在.proto文件中使用这些预留标识号,编译时就会报警。
指定字段规则:字段的修饰符包含三种类型,分别是:
required:一个格式良好的消息一定要含有1个这种字段。表示该值是必须要设置的;
optional:消息格式中该字段可以有0个或1个值(不超过1个)。
repeated:在一个格式良好的消息中,这种字段可以重复任意多次(包括0次)。重复的值的顺序会被保留。表示该值可以重复,相当于Go中的slice。
【注意:】使用required弊多于利;在实际开发中更应该使用optional和repeated而不是required。
添加更多消息类型 在同一个.proto文件中,可以定义多个消息类型。多个消息类型分开定义即可。
边栏推荐
- touchID 和 FaceID~1
- iPhone 各大机型设备号
- Uniapp development, upload pictures in the app and send them directly to OSS
- ES6 syntax -- Deconstruction assignment
- 通信感知一体化应用场景、关键技术和网络架构
- Dhfs read / write process
- 同学们不要全抄我的代码哈 记得改一改 要不我俩都要G
- Today's codefarmer girl summed up the notes on the difference between the method of jQuery processing cache and the method of event delegation
- 4 搜索插入位置
- 11 错误的集合
猜你喜欢
随机推荐
Database programming (MySQL) of node, adding, deleting, modifying and querying
ethereum rpc
金融学 杂项记录
axs火爆,还有哪些打金游戏(上)
9 无人机方阵
Today's codefarmer girl summed up the notes on the difference between the method of jQuery processing cache and the method of event delegation
软件漏洞分析入门(四)
元宇宙会给万亿市场的音乐产业带来哪些变化?
iPhone 各大机型设备号
5G专网在智慧医疗中的应用
Dhfs read / write process
感通融合系统中保障公平度的时间与功率分配方法
WKWebView 设置自定义UserAgent正确姿势
Classification and use of express Middleware
通信感知一体化应用场景、关键技术和网络架构
07-BTC-挖矿
Uniapp development, upload pictures in the app and send them directly to OSS
Today's code farmer girl learned about nodejs and repl interactive interpreter
What is "digital collection"?
Red sun range 2








