[feat] Invoke 取消 context 参数
This commit is contained in:
parent
af325a0ba6
commit
3d596598c6
@ -26,7 +26,7 @@ type Grpcall struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构建请求函数
|
// 构建请求函数
|
||||||
func (this Grpcall) Invoke(ctx context.Context, service, method, data string, headers []string) (*Response, error) {
|
func (this Grpcall) Invoke(service, method, data string, headers []string) (*Response, error) {
|
||||||
// 获取 gRPC 服务方法描述信息
|
// 获取 gRPC 服务方法描述信息
|
||||||
mtd, err := this.GetServiceMethodDescriptor(service, method)
|
mtd, err := this.GetServiceMethodDescriptor(service, method)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -35,7 +35,7 @@ func (this Grpcall) Invoke(ctx context.Context, service, method, data string, he
|
|||||||
|
|
||||||
md := this.MakeMetadata(headers)
|
md := this.MakeMetadata(headers)
|
||||||
|
|
||||||
ctx = metadata.NewOutgoingContext(ctx, md)
|
ctx := metadata.NewOutgoingContext(context.Background(), md)
|
||||||
|
|
||||||
anyResolver, err := this.GetAnyResolver()
|
anyResolver, err := this.GetAnyResolver()
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package grpcall
|
package grpcall
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -43,9 +42,7 @@ func TestGetServiceMethods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInvokeUnary(t *testing.T) {
|
func TestInvokeUnary(t *testing.T) {
|
||||||
ctx := context.Background()
|
if resp, err := gc.Invoke("User.UserResourceStatus", "TestInt64Value", `123`, nil); err != nil {
|
||||||
|
|
||||||
if resp, err := gc.Invoke(ctx, "User.UserResourceStatus", "TestInt64Value", `123`, nil); err != nil {
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
} else {
|
} else {
|
||||||
t.Log(resp.Data())
|
t.Log(resp.Data())
|
||||||
@ -53,9 +50,7 @@ func TestInvokeUnary(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInvokeServStream(t *testing.T) {
|
func TestInvokeServStream(t *testing.T) {
|
||||||
ctx := context.Background()
|
if resp, err := gc.Invoke("User.UserResourceStatus", "GetEvent", `{}`, nil); err != nil {
|
||||||
|
|
||||||
if resp, err := gc.Invoke(ctx, "User.UserResourceStatus", "GetEvent", `{}`, nil); err != nil {
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
} else if recv, err := resp.Recv(); err != nil {
|
} else if recv, err := resp.Recv(); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@ -81,9 +76,7 @@ func TestInvokeServStream(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestInvokeBidiStream(t *testing.T) {
|
func TestInvokeBidiStream(t *testing.T) {
|
||||||
ctx := context.Background()
|
if resp, err := gc.Invoke("User.UserResourceStatus", "TestBidiStream", `"hello"`, nil); err != nil {
|
||||||
|
|
||||||
if resp, err := gc.Invoke(ctx, "User.UserResourceStatus", "TestBidiStream", `"hello"`, nil); err != nil {
|
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
} else if send, err := resp.Send(); err != nil {
|
} else if send, err := resp.Send(); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user