linux下搭建goprotobuf
chenglinhust · · 2364 次点击 · · 开始浏览1. 搭建go语言环境
2. 搭建protobuf环境
3. 搭建goprotobuf
go get code.google.com/p/goprotobuf/{proto,protoc-gen-go}
go install code.google.com/p/goprotobuf/proto
然后就可以在 $GO_PATH/bin下找到 protoc-gen-go 这个程序,那么就可以实用protoc-gen-go 进行go语言的proto文件的自动生成了。
go1.0 使用: protoc-gen-go --go_out=. hellowrold.proto
go1.1 直接实用以下命令
protoc --go_out=. hellowrold.proto
proto文件:
message helloworld
{
required int32 id = 1; // ID
required string str = 2; // str
optional int32 opt = 3; //optional field
}
注意: package lm; 因此必须放到lm目录下(参考proto规范) ,在lm下面使用命令生成文件
protoc --go_out=. hellowrold.proto
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
1. 搭建go语言环境
2. 搭建protobuf环境
3. 搭建goprotobuf
go get code.google.com/p/goprotobuf/{proto,protoc-gen-go}
go install code.google.com/p/goprotobuf/proto
然后就可以在 $GO_PATH/bin下找到 protoc-gen-go 这个程序,那么就可以实用protoc-gen-go 进行go语言的proto文件的自动生成了。
go1.0 使用: protoc-gen-go --go_out=. hellowrold.proto
go1.1 直接实用以下命令
protoc --go_out=. hellowrold.proto
proto文件:
message helloworld
{
required int32 id = 1; // ID
required string str = 2; // str
optional int32 opt = 3; //optional field
}
注意: package lm; 因此必须放到lm目录下(参考proto规范) ,在lm下面使用命令生成文件
protoc --go_out=. hellowrold.proto