这里介绍protobuf的工具的下载与使用,以及结合grpc进行微服务框架的编写!!!
protoc的程序的下载链接如下:
Releases · protocolbuffers/protobuf · GitHubProtocol Buffers - Google's data interchange format - Releases · protocolbuffers/protobuf
https://github.com/protocolbuffers/protobuf/releases选择对应的操作系统类型的protoc下载即可!!!
这里需要:github.com/golang/protobuf/protoc-gen-go这个库
GitHub - golang/protobuf: Go support for Google's protocol buffersGo support for Google's protocol buffers. Contribute to golang/protobuf development by creating an account on GitHub.
https://github.com/golang/protobuf
需要注意的是:
protoc的版本要和protoc-gen-go的版本要一致才行,不然生成出来的代码会出错!!!
go get github.com/golang/protobuf/protoc-gen-go
编写proto文件:
helloworld.proto:
- syntax = "proto3";
-
- message HelloRequest{
- string name = 1;
-
- }