在go语言里使用thrift做远程通讯

一.准备和编写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框架完美实现跨语言调用

转载于:https://www.cnblogs.com/ananclub/p/3399328.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值