Go使用ProtoBuffhtml
發現Google Code上面有針對Go語言的Protobuff實現linux
code.google.com/p/goprotobufshell
下面說下安裝過程:windows
go get code.google.com/p/goprotobuf測試
以後提示no Go source filesgoogle
執行spa
go install code.google.com/p/goprotobuf/proto插件
在Go的安裝目錄pkg下產生對應路徑的proto.a文件code
執行htm
go install code.google.com/p/goprotobuf/protoc-gen-go
在Go的安裝目錄pkg下產生對應路徑的protoc-gen-go文件夾
在Go的bin目錄產生protoc-gen-go.exe,使用google protobuf編譯產生的protoc程序,將protoc.exe和protoc-gen-go.exe拷貝至同一目錄
執行 protoc --plugin=protoc-gen-go=protoc-gen-go.exe --go_out=./ xx.proto
參考:
http://www.cnblogs.com/zhangqingping/archive/2012/10/28/2743274.html
ps:以前一直是linux能夠正確執行,windows不能夠,緣由是linux不須要添加--plugin=protoc-gen-go=protoc-gen-go.exe選項指定插件的路徑
經測試,protobuf 2.3和2.4是兼容protoc-gen-go的
貼一個批處理:protogo.bat
@echo off if not exist %1 goto :Use if not exist %2 goto :Use if not exist %3 goto :Use %GOROOT%\bin\protoc.exe --plugin=protoc-gen-go=%GOROOT%\bin\protoc-gen-go.exe --go_out=%1 --proto_path=%2 %3 goto :End :Use echo use: 一、go-out-dir 二、proto-dir 三、proto-file :End