thrift go 报错not enough arguments in call to oprot.Flush

go 作为服务端与php通信,服务端代码如下s.go

package main
  
import (
    "hello/world"
    "fmt"
    "git.apache.org/thrift.git/lib/go/thrift"
)

const (
    NetworkAddr = "0.0.0.0:10086"
)

type helloThrift struct {
}
func (this *helloThrift) HelloName(name string) (string,err){
        return (name + "111"),nil;
}

func main() {
    transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
    protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
    //protocolFactory := thrift.NewTCompactProtocolFactory()

    serverTransport, err := thrift.NewTServerSocket(NetworkAddr)
    if err != nil {
        fmt.Println("Error!", err)
        os.Exit(1)
    }

    handler := &idoallThrift{}
    processor := HelloWorld.NewHelloWorldProcessor(handler)

    server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
    fmt.Println("thrift server in", NetworkAddr)
    server.Serve()
}

执行go run s.go
但是报错如下:

# hello/world
hello/world/helloworld.go:77:20: not enough arguments in call to oprot.Flush
    have ()
    want (context.Context)
hello/world/helloworld.go:101:15: cannot assign 1 values to 2 variables
hello/world/helloworld.go:147:34: cannot use helloWorldProcessorHelloName literal (type *helloWorldProcessorHelloName) as type thrift.TProcessorFunction in assignment:
    *helloWorldProcessorHelloName 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)
hello/world/helloworld.go:157:27: not enough arguments in call to processor.Process
    have (int32, thrift.TProtocol, thrift.TProtocol)
    want (context.Context, int32, thrift.TProtocol, thrift.TProtocol)
hello/world/helloworld.go:165:13: not enough arguments in call to oprot.Flush
    have ()
    want (context.Context)
hello/world/helloworld.go:182:14: not enough arguments in call to oprot.Flush
    have ()
    want (context.Context)
hello/world/helloworld.go:195:14: not enough arguments in call to oprot.Flush
    have ()
    want (context.Context)
hello/world/helloworld.go:209:23: not enough arguments in call to oprot.Flush
    have ()
    want (context.Context)

有人遇到过这个问题嘛?hello/world/helloworld.go是通过thrift生成的。。。。

阅读 10.3k
4 个回答
新手上路,请多包涵

到GOPATH thrift目录下 然后git checkout 0.10

新手上路,请多包涵

这是由于thrift版本库不一致导致的问题。你可以下载0.9.2的thrift库,然后用下面的方法产生新的文件如下:
go get -u github.com/oyi812/apache-thrift-0.9.2-lib-go-thrift/thrift

thrift -out . --gen go:thrift_import=github.com/oyi812/apache-thrift-0.9.2-lib-go-thrift/thrift thrift_file/example.thrift

新手上路,请多包涵

我的也是这种错误,你的解决了吗?我用的thrift0.9和0。11都是这样的,我go1.9

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏