geektutu / blog

极客兔兔的博客,Coding Coding 创建有趣的开源项目。
https://geektutu.com
Apache License 2.0
166 stars 21 forks source link

Go Protobuf 简明教程 | 快速入门 | 极客兔兔 #56

Open geektutu opened 4 years ago

geektutu commented 4 years ago

https://geektutu.com/post/quick-go-protobuf.html

protobuf 即 Protocol Buffers,是一种轻便高效的结构化数据存储格式,与语言、平台无关,可扩展可序列化。protobuf 性能和效率大幅度优于 JSON、XML 等其他的结构化数据格式。protobuf 是以二进制方式存储的,占用空间小,但也带来了可读性差的缺点。protobuf 在通信协议和数据存储等领域应用广泛。本文介绍的是 Protocol Buffers 3 (protobuf3, proto3) 的安装和基本语法,以及如何在 Go 语言使用。

southpolemonkey commented 4 years ago

喜欢博主简单明了的总结

geektutu commented 4 years ago

@southpolemonkey 感谢你的认可, 这样写适合快速熟悉,如果需要重度使用,再参考官方文档就会容易多了~

HuntSweet commented 4 years ago

name, male, scores 是该类型的 2 个字段

geektutu commented 4 years ago

@HuntSweet name, male, scores 是该类型的 2 个字段

感谢指出,今天修正~

haolipeng commented 3 years ago

在go的1.14版本以后,proto文件中不添加go_package 会报错 报错信息如下: Please specify either: • a "go_package" option in the .proto source file, or • a "M" argument on the command line. 解决方法: option go_package = "./" 或者填写自己的包路径也行如option go_package = "http://github.com/package/name"

Hangzhi commented 3 years ago

sudo apt install protobuf-compiler

protoc --version

c-jf commented 2 years ago

大佬,你博客的这些教程有随着版本更新而更新吗,比如说protobuf,好像最新的版本必须在proto文件中加入 option go_package 才能生成pb文件,旧版本就不需要,这个东西坑了我好长时间,哭

8vd8 commented 2 months ago

我的是windows系统,然后前面那个proto部分,大家可以在proto文件中,在package代码下面一行写一个option go_package = "/main";然后在命令行protoc --go_out=. student.proto 写这个命令就可以直接生成了