您的位置:首页 > 编程语言 > Go语言

在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框架完美实现跨语言调用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: