参考文章:https://developers.google.com/protocol-buffers/docs/gotutorial
1.执行指令:
go env
go get github.com/golang/protobuf/protoc-gen-go
如果是windows:会下载protoc-gen-go.exe到$GOPATH/bin下,把它拷贝到$PATH,它只是protobuf3的golang插件,还不是真正的编译器
如果是linux:会下载protoc-gen-go到$GOPATH/bin下,把它拷贝到$PATH,它只是protobuf3的golang插件,还不是真正的编译器
2.下载protoc,地址https://github.com/google/protobuf/releases,里面可以找到win/linux/mac的二进制文件,
我们需要protoc-3.1.0-win32.zip或者protoc-3.1.0-linux-x86_64.zip,把里面的protoc.exe(其它文件不需要)拷贝到PATH下面
3.生成c++和golang的代码(只有golang需要插件,其它语言不需要)
测试代码:https://github.com/wjx0912/GoLangUtils/blob/master/project_protobuf3/proto/addressbook.proto
protoc --go_out . addressbook.proto
protoc --cpp_out . addressbook.proto
protoc --csharp_out . addressbook.proto
protoc --java_out . addressbook.proto
protoc --js_out . addressbook.proto
protoc --objc_out . addressbook.proto
protoc --ruby_out . addressbook.proto
4.golang的测试代码:https://github.com/wjx0912/GoLangUtils/tree/master/project_protobuf3
5.proto3文档:https://developers.google.com/protocol-buffers/docs/proto3
go api文档:https://godoc.org/github.com/golang/protobuf/proto
https://github.com/google/protobuf/blob/master/examples/addressbook.proto