go语言使用proto

栏目: Go · 发布时间: 6年前

安装

go get -d -u github.com/golang/protobuf/protoc-gen-go
go install github.com/golang/protobuf/protoc-gen-go

定义proto文件

syntax = "proto3";

package model;

message SayParam {
    string msg = 1;
}

message Pair {
    int32 key = 1;
    string values = 2;
}

message SayResponse {
    string msg = 1;
    // 数组
    repeated string values = 2;
    // map
    map<string, Pair> header = 3;
    RespType type = 4;
}

enum RespType {
    NONE = 0;
    ASCEND = 1;
    DESCEND = 2;
}

// 服务接口
service Say {
    rpc Hello(SayParam) returns (SayResponse) {}
}

生成 go 代码

protoc --proto_path=/home/www/go/src --go_out=. /home/www/go/src/protoTest/common.proto
proto_path
--proto_path=PATH Specify the directory in which to search for  imports. May be specified multiple times;  directories will be searched in order. If not  given, the current working directory is used.  If not found in any of the these directories,  the --descriptor_set_in descriptors will be  checked for required proto file.
  • 表示导入包的寻找路径
  • 命令的最后参数是proto文件路径

参考资料


以上所述就是小编给大家介绍的《go语言使用proto》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

天涯虚拟社区

天涯虚拟社区

刘华芹 / 民族出版社 / 2005-11 / 23.00元

网络空间很复杂,好多人并不完全了解或者只是了解到一些皮毛。比如说好多人对于见网友一事总是抱着浪漫或者暖昧的想法,而事实却并不总是想象的那样。作者在做虚拟社区研究甚至是在有这个想法之前并不常呆在网上,互联网对于作者来说就是查查资料、收发信年、看看新闻的工具。担是看着越来越多的人把时间花在网上,一处文化上的直觉告诉作者:有一种新的生活方式产生了。强烈的好奇心驱使着作者走到了网上,走到了天涯虚拟社区,并......一起来看看 《天涯虚拟社区》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具