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 get  git.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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM