永夜海 发表于 2018-9-20 13:42:09

win7环境下,golang thrift demo代码编译不通过

  用官方的教程代码:http://thrift.apache.org/tutorial/go
  用网友提供的代码:Golang RPC 之 Thrift
  都出现如下情况
  状况1:
  编辑器中就会提醒 Cannot use 'processor' (type *FormatDataProcessor) as type TProcessor
  状况2:
  # ThriftDemo/example
  example\example.go:232: cannot use formatDataProcessorDoFormat literal (type *formatDataProcessorDoFormat) as type thrift.TProcessorFunction in assignment:
  *formatDataProcessorDoFormat does not implement thrift.TProcessorFunction (wrong type for Process method)
  have Process(int32, thrift.TProtocol, thrift.TProtocol) (bool, thrift.TException)
  want Process(context.Context, int32, thrift.TProtocol, thrift.TProtocol) (bool, thrift.TException)
  example\example.go:240: not enough arguments in call to processor.Process
  have (int32, thrift.TProtocol, thrift.TProtocol)
  want (context.Context, int32, thrift.TProtocol, thrift.TProtocol)
  分析原因:
  一开始我以为是和环境有关系,我今天在公司用的是win7 64 + Go 1.9.1(发现官方server代码编译不过,从1.8.0升级上来的) + thrift 0.10.0官方demo和网上demo怎么都编译不过server端,client端没有问题, 刚在家里Mac上 Go 1.8.0 + thrift 0.10.0同样的代码,没有问题,但是我忽略的另外一个问题,thrift lib中的go文件 ,公司的是删了今天重新下的,家里的是好几个月之前
  推测原因:
  thrift是好几个月前安装的,而我最近go getgit.apache.org/thrift.git/lib/go/thrift 更新了代码,造成的代码版本不一致
  解决方案:
  最终得出结论,是thrift版本和git.apache.org/thrift.git/lib/go/thrift的版本不一致造成的,今天在win7平台上也跑过了,我直接在GOPATH环境下
  先删除 git.apache.org/thrift.git/目录,然后
  mkdir -p git.apache.org/thrift.git/lib/go/thrift
  最后,将thrift安装目录下的代码拷贝过去,能通过
  我的thrift的目录:
  D:\thrift\src\thrift\lib\go\thrift

页: [1]
查看完整版本: win7环境下,golang thrift demo代码编译不通过