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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

C++沉思录

C++沉思录

Andrew Koenig、Barbara Moo / 黄晓春、孟岩(审校) / 人民邮电出版社 / 2002-11-01 / 50.00元

《C++ 沉思录》集中反映了C++的关键思想和编程技术,不仅告诉你如何编程,还告诉你为什么要这样编程。本书曾出现在众多的C++专家推荐书目中。 这将是C++程序员的必读之作。因为: 它包含了丰富的C++思想和技术,从详细的代码实例总结出程序设计的原则和方法。 不仅教你如何遵循规则,还教你如何思考C++编程。 既包括面向对象编程也包括泛型编程。 探究STL这一近年来C++最重要的新成果的内在思想。一起来看看 《C++沉思录》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码