protoc 命令來自 https://github.com/google/protobuf, 由於這里沒有 go 的產生代碼, go的產生代碼在 protoc-gen-go (https://github.com/golang/protobuf/)這里。
$ protoc --go_out=./go/ ./proto/helloworld.proto
$ protoc --go_out=plugins=grpc:./go2/ ./proto/helloworld.proto
上面兩個命令,第一個產生的只是 protobuffer 文件序列化和反序列化的代碼。
第二個產生的則除了第一個的代碼外,還增加服務器和客戶端通訊、實現的公共庫代碼。
https://github.com/grpc/grpc-go 這里的代碼對應的包名是: google.golang.org/grpc 這里只是一些公共函數庫, protoc 和 protoc-gen-go 這兩個工具都不在這里。
產生 protoc-gen-go 這個工具的方法如下:
$ go get -u github.com/golang/protobuf/protoc-gen-go