0. environment
- go使用1.9版本,已配置GOPATH为 ~/go
1. protobuf
- 下载:https://github.com/protocolbuffers/protobuf/releases
- cd protobuf-3.17.3
- ./configure --prefix=/usr/local/protobuf
- make
- sudo make install
- 添加:sudo open -e ~/.bash_profile
export PROTOBUF=/usr/local/protobuf export PATH=$PROTOBUF/bin:$PATH
- 测试:source ~/.bash_profile && protoc --version
2. protobuf-go-plugin
- 进入GOPATH:cd ~/go/src/github.com/golang
- git clone https://gitee.com/zhang_sining/protobuf-go.git
- go build && go install
- 测试:
protoc --go_out=./ *.proto
- 示例文件: myproto.proto
syntax = "proto3"; package pb; option go_package = "/"; enum Week { Monday = 0; Tuesday = 1; } message Student { int32 age = 1; string name = 2; People p = 3; repeated int32 score = 4; Week w = 5; oneof data { string teacher = 6; string class = 7; } } message People { int32 weight = 1; }
3. protobuf-jetbrains-plugin
- 下载:https://github.com/ksprojects/protobuf-jetbrains-plugin/releases/tag/v0.13.0
- 直接拖进goland,重启goland生效
4. errors
- cannot find package "google.golang.org/protobuf/types/descriptorpb
解决:
protobuf-go路径问题
cd ~/go/src && mkdir google.golang.org && cd google.golang.org
将前面的protobuf-go放到这里并改名为protobuf - cannot find package “google/protobuf”
解决:
安装中一切正常的话应该是没source