参考 https://www.cnblogs.com/pluse/p/7761365.html
利用thrift rpc进行C++与Go的通信的过程中,报错
# testRPCX
.\main.go:4:2: imported and not used: "context"
.\main.go:29:43: not enough arguments in call to client.GetCurrtentTime
have ()
want (context.Context)
错误: 进程退出代码 2.
修改Go Client代码如下
即为修改 timeResult, err := client.GetCurrtentTime() 为 client.GetCurrtentTime(context.Background())
package main
import (
"context" //添加
"fmt"
"os"
"timerpc"
"github.com/apache/thrift/lib/go/thrift"
)
func main() {
// get socket
socket, err := thrift.NewTSocket("127.0.0.1:9090")
// choose transport
transport := thrift.NewTBufferedTransport(socket, 8192)
// serialize
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
client := timerpc.NewTimeServeClientFactory(transport, protocolFactory)
// open connect
transport.Open()
defer socket.Close()
//timeResult, err := client.GetCurrtentTime() 源代码,修改为
timeResult, err := client.GetCurrtentTime(context.Background())
if err != nil {
fmt.Println(err.Error())
os.Exit(2)
}
fmt.Println(timeResult)
}