鍍金池/ 問(wèn)答/PHP  GO/ thrift go 報(bào)錯(cuò)not enough arguments in call

thrift go 報(bào)錯(cuò)not enough arguments in call to oprot.Flush

go 作為服務(wù)端與php通信,服務(wù)端代碼如下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()
}

執(zhí)行g(shù)o run s.go
但是報(bào)錯(cuò)如下:

# 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)

有人遇到過(guò)這個(gè)問(wèn)題嘛?hello/world/helloworld.go是通過(guò)thrift生成的。。。。

回答
編輯回答
生性

到GOPATH thrift目錄下 然后git checkout 0.10

2017年4月22日 07:00
編輯回答
離夢(mèng)

我的也是這種錯(cuò)誤,你的解決了嗎?我用的thrift0.9和0。11都是這樣的,我go1.9

2017年9月18日 08:47
編輯回答
風(fēng)清揚(yáng)

最近也遇到這個(gè)問(wèn)題,可以參考一這篇文章 http://www.cnblogs.com/liugx/...

2018年6月21日 21:40
編輯回答
命多硬

這是由于thrift版本庫(kù)不一致導(dǎo)致的問(wèn)題。你可以下載0.9.2的thrift庫(kù),然后用下面的方法產(chǎn)生新的文件如下:
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

2017年9月9日 04:13