在go语言里使用thrift做远程通讯
2013-10-31 14:55
736 查看
一.准备和编写IDL
thrift的介绍和安装见上文
thrift支持的数据类型
基本类型
bool: A boolean value (true or false)
byte: An 8-bit signed integer
i16: A 16-bit signed integer
i32: A 32-bit signed integer
i64: A 64-bit signed integer
double: A 64-bit floating point number
string: A text string encoded using UTF-8 encoding
Struct 包含其他数据类型的结构体,与c语言的struct类同
Containers 容器
list
set
map
Exceptions 异常
Services 服务,也就是提供给远程调用的方法
IDL定义的例子demo.thrift:
//namespace go demo.rpc
service RpcService{
list<string> funCall(1:i64 callTime, 2:string funCode, 3:map<string, string> paramMap),
}
IDL文件支持include
注释支持shell和c两种语言的注释方式
#comment
//comment
/*comment*/
二.thrift编译器的使用
thrift --gen go -o rpcgo demo.thrift
--gen参数指定输出语言 -o指定输出目录
go语言有两个额外的参数
package_prefix= Package prefix for generated files.
thrift_import= Override thrift package import path (default:git.apache.org/thrift.git/lib/go/thrift)
使用方法
thrift --gen go:package_prefix=ownprefix,thrift_import=ownthriftpackage -o rpcgo demo.thrift
参考:Golang通过Thrift框架完美实现跨语言调用
thrift的介绍和安装见上文
thrift支持的数据类型
基本类型
bool: A boolean value (true or false)
byte: An 8-bit signed integer
i16: A 16-bit signed integer
i32: A 32-bit signed integer
i64: A 64-bit signed integer
double: A 64-bit floating point number
string: A text string encoded using UTF-8 encoding
Struct 包含其他数据类型的结构体,与c语言的struct类同
Containers 容器
list
set
map
Exceptions 异常
Services 服务,也就是提供给远程调用的方法
IDL定义的例子demo.thrift:
//namespace go demo.rpc
service RpcService{
list<string> funCall(1:i64 callTime, 2:string funCode, 3:map<string, string> paramMap),
}
IDL文件支持include
注释支持shell和c两种语言的注释方式
#comment
//comment
/*comment*/
二.thrift编译器的使用
thrift --gen go -o rpcgo demo.thrift
--gen参数指定输出语言 -o指定输出目录
go语言有两个额外的参数
package_prefix= Package prefix for generated files.
thrift_import= Override thrift package import path (default:git.apache.org/thrift.git/lib/go/thrift)
使用方法
thrift --gen go:package_prefix=ownprefix,thrift_import=ownthriftpackage -o rpcgo demo.thrift
参考:Golang通过Thrift框架完美实现跨语言调用
相关文章推荐
- go语言net包rpc远程调用的使用示例
- go语言使用sftp包上传文件和文件夹到远程服务器
- go语言net包rpc远程调用的使用
- 在Go语言程序中使用gojson来解析JSON格式文件
- 使用Sublime text 3打造一个小巧但强大的Go语言开发IDE
- Go语言标准库Json的使用.
- golang实战使用gin+xorm搭建go语言web框架restgo详解10 使用restgo搭建后台管理系统
- go语言使用go-sciter创建桌面应用(三) 事件处理,函数与方法定义,go与tiscript之间相互调用
- go语言中log包的使用
- go语言 xorm框架 postgresql 使用实例以及详细注解
- go 语言之ReadFromUDP使用
- Go语言 IDE之Gogland配置使用
- go语言, defer con.Close() 使用之一
- Go语言使用PostgreSQL数据库
- 跨语言通信框架Apache Thrift在PHP中的使用
- Hprose 是轻量级跨语言跨平台的面向对象的高性能远程动态通讯中间件
- 使用Python语言通过Thrift 网关操作HBase
- Go语言下使用 nats 消息机制
- Go语言中使用SQLite数据库
- golang实战使用gin+xorm搭建go语言web框架restgo详解3 系统常用配置参数