thrift 遇到的坑

1,not enough arguments in call to oprot.Flush
have ()
want (context.Context)
原因idl 编译器与thrift lib 的版本不一致,生成idl用0.9.2 ,thrift go lib 版本是0.10.0
解决方案
~/goLang/src/git.apache.org/thrift.git$git tag
0.10.0
0.11.0
0.2.0
0.3.0
0.4.0
0.5.0
0.6.0
0.6.1
0.7.0
0.8.0
0.9.0
0.9.1
0.9.2
0.9.3
hier
git checkout 0.9.2
编译通过
2,编译完成,运行失败
./client: line 1: syntax error near unexpected token newline'
./client: line 1:
!'
原因:main函数(只能应用于package main)
解决方案:改main函数包名为main
3,接口实现不对
cannot use EchoServerImp literal (type *EchoServerImp) as type echo.Echo in argument to echo.NewEchoProcessor:
*EchoServerImp does not implement echo.Echo (wrong type for Echo method)
have Echo(context.Context, *echo.EchoReq) (*echo.EchoRes, error)
want Echo(*echo.EchoReq) (*echo.EchoRes, error)
原因:实现接口的时候方法多了一个参数
4,client: Expected protocol id 82 but got 00
server: error processing request: Incorrect frame size (2183201028)
两边idl 不对应
5,cannot find package "golang.org/x/net/context" in any of:
.../projects/go-projects/src/github.com/blevesearch/bleve/vendor/golang.org/x/net/context
(vendor tree)
解决方案:cd src
mkdir golang.org
cd golang.org
mkdir x
cd x
git clone git@github.com:golang/net.git --depth 1
6,non-standard import "github.com/mattn/go-sqlite3" in standard package "iislog"
GO有两个路径需要定义,一个是GO自身的安装目录 GOROOT,这个目录只能放标准包,也就是”standart packages“。另一个是GOPATH,也就是工作目录,这里用来放第三方包,也就是“non-standard packages”。
http://mirrors.hust.edu.cn/apache/thrift/0.9.3/
7,GOPATH=`pwd` /home/xiaoju/go/bin/go get github.com/golang/mock/gomock
package golang.org/x/net/context: unrecognized import path "golang.org/x/net/context" (https fetch: Get https://golang.org/x/net/context?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
$mkdir -p src/golang.org/x
git clone https://github.com/golang/mock
8,关于gopath中的目录
golang_org golang.org google.golang.org
三个优先使用 golang.org
9.thrift 0.9.3 编译只能用 go version go1.10.4 linux/amd64 版本才能编译通过
10,编译go
git clone https://github.com/golang/go
cd go
git tag
git checkout go1.9
export GOROOT_BOOTSTRAP="/home/xiaoju/go1.8.1/"
./make.bash
8,# command-line-arguments
src/github.com/xiazemin/thrift/gen-go/echo/framed/server/echo.go:34:29: cannot use thrift.NewTFramedTransport(thrift.NewTTransportFactory()) (type *thrift.TFramedTransport) as type thrift.TTransportFactory in argument to thrift.NewTSimpleServer4:
*thrift.TFramedTransport does not implement thrift.TTransportFactory (missing GetTransport method)
src/github.com/xiazemin/thrift/gen-go/echo/framed/server/echo.go:34:57: cannot use thrift.NewTTransportFactory() (type thrift.TTransportFactory) as type thrift.TTransport in argument to thrift.NewTFramedTransport:
thrift.TTransportFactory does not implement thrift.TTransport (missing Close method)
解决方案:用 thrift.NewTFramedTransport(thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())), 替代
thrift.NewTFramedTransport(thrift.NewTTransportFactory()),
但是 出现:
# command-line-arguments
src/github.com/xiazemin/thrift/gen-go/echo/framed/server/echo.go:34:29: cannot use thrift.NewTFramedTransport(thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())) (type *thrift.TFramedTransport) as type thrift.TTransportFactory in argument to thrift.NewTSimpleServer4:
*thrift.TFramedTransport does not implement thrift.TTransportFactory (missing GetTransport method)
src/github.com/xiazemin/thrift/gen-go/echo/framed/server/echo.go:34:63: cannot use thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) (type thrift.TTransportFactory) as type thrift.TTransport in argument to thrift.NewTFramedTransport:
thrift.TTransportFactory does not implement thrift.TTransport (missing Close method)
应该是:thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
9,failed: EOF
原因传输协议不一样:
protocolFactory := thrift.NewTCompactProtocolFactory()
protocolFactory :=thrift.NewTBinaryProtocolFactoryDefault()
不能通信
10,Request error reading struct: error reading field 0: Not enought frame size 3 to read 8 bytes
原因: idl 定义不一致,改成一致才可以



Category web