linux下搭建goprotobuf

linux下搭建goprotobuf

1.  搭建go语言环境


 参考官网:http://golang.org/doc/install
  主要是设置好GO_PATH这个变量,这个就是你的工作环境目录,可以使用go env来查询设置好了没。

2.  搭建protobuf环境

 这个可以参考我的博客:http://blog.csdn.net/chdhust/article/details/38729161

3.  搭建goprotobuf

   

go get code.google.com/p/goprotobuf/{proto,protoc-gen-go}

  go install  code.google.com/p/goprotobuf/proto

  

  然后就可以在 $GO_PATH/bin下找到 protoc-gen-go 这个程序,那么就可以实用protoc-gen-go 进行go语言的proto文件的自动生成了。

go1.0 使用: protoc-gen-go --go_out=. hellowrold.proto 

go1.1 直接实用以下命令

protoc --go_out=. hellowrold.proto

 

proto文件:

package lm; 
message helloworld 

    required int32     id = 1;  // ID 
    required string    str = 2;  // str 
    optional int32     opt = 3;  //optional field 

}  

 

注意: package lm; 因此必须放到lm目录下(参考proto规范) ,在lm下面使用命令生成文件

protoc --go_out=. hellowrold.proto

 

你可能感兴趣的:(linux下搭建goprotobuf)