@
Raymon111111 我知道怎么玩了,
正常情况下是这样
```
transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transport, err := thrift.NewTSocket(net.JoinHostPort(HOST, PORT))
useTransport,_ := transportFactory.GetTransport(transport)
transport.Open()
client := usersrv.NewUserInfoServiceClientFactory(useTransport, protocolFactory)
然后 client.GetUserById(context.TODO(), id)
```
参考了 gprc.Invoke,观察了下 thrift 的调用方法
```
type UserInfoServiceClient struct {
c thrift.TClient
}
// Deprecated: Use NewUserInfoService instead
func NewUserInfoServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *UserInfoServiceClient {
return &UserInfoServiceClient{
c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)),
}
}```
后来,直接自己构造里面的 thrift.TClient,
stClient:=thrift.NewTStandardClient(protocolFactory.GetProtocol(useTransport), protocolFactory.GetProtocol(useTransport))
var _args0 usersrv.UserInfoServiceGetUserByNameArgs
_args0.Namea = "123"
var _result1 usersrv.UserInfoServiceGetUserByIdResult
stClient.Call(context.Background(),"getUserById", &_args0, &_result1);
//if err = stClient.Call(context.Background(),"getUserById", &_args0, &_result1); err != nil {
// fmt.Println(err)
// return
//}
fmt.Println(_result1.GetSuccess())
前提是知道入参跟出参是什么,不过自定义网关消息的结构是通用的。比如说现在是
usersrv.UserInfoServiceGetUserByNameArgs,usersrv.UserInfoServiceGetUserByIdResult,
以后通用起来可能就是 ApiGateway.MessageRequest , ApiGateway.MessageResponse 这样。只需要接口定义时候确定成通用的格式就好了。