一、安裝庫文件protobuf,地址:https://github.com/protocolbuffers/protobuf/releaseslinux
我電腦是deepin 64位的,因此我直接下載https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zipgit
$wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip $mkdir protoc $cd protoc $unzip protoc-3.9.1-linux-x86_64.zip $cd bin $cp protoc /home/dongge/go-work/bin/#複製到$GOPATH/bin目錄下 $protoc --version
二、安裝插件github
$go get github.com/golang/protobuf/protoc-gen-go
gogoprotobuf有兩個插件能夠使用golang
protoc-gen-gogo:和protoc-gen-go生成的文件差很少,性能也幾乎同樣(稍微快一點點)shell
protoc-gen-gofast:生成的文件更復雜,性能也更高(快5-7倍)性能
//gogo
$go get github.com/gogo/protobuf/protoc-gen-gogo
//gofast
$go get github.com/gogo/protobuf/protoc-gen-gofast
三、安裝gogoprotobuf庫文件spa
$go get github.com/gogo/protobuf/proto
$go get github.com/gogo/protobuf/gogoproto //這個不裝也不要緊
四、生成go文件插件
//gogo $protoc --gogo_out=. *.proto //gofast $protoc --gofast_out=. *.proto