diff --git a/grpcall.go b/grpcall.go index 2647420..29ddc4a 100644 --- a/grpcall.go +++ b/grpcall.go @@ -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 服务方法描述信息 mtd, err := this.GetServiceMethodDescriptor(service, method) if err != nil { @@ -35,7 +35,7 @@ func (this Grpcall) Invoke(ctx context.Context, service, method, data string, he md := this.MakeMetadata(headers) - ctx = metadata.NewOutgoingContext(ctx, md) + ctx := metadata.NewOutgoingContext(context.Background(), md) anyResolver, err := this.GetAnyResolver() diff --git a/grpcall_test.go b/grpcall_test.go index 7a5fe3b..1e3cd47 100644 --- a/grpcall_test.go +++ b/grpcall_test.go @@ -1,7 +1,6 @@ package grpcall import ( - "context" "fmt" "os" "testing" @@ -43,9 +42,7 @@ func TestGetServiceMethods(t *testing.T) { } func TestInvokeUnary(t *testing.T) { - ctx := context.Background() - - if resp, err := gc.Invoke(ctx, "User.UserResourceStatus", "TestInt64Value", `123`, nil); err != nil { + if resp, err := gc.Invoke("User.UserResourceStatus", "TestInt64Value", `123`, nil); err != nil { t.Error(err) } else { t.Log(resp.Data()) @@ -53,9 +50,7 @@ func TestInvokeUnary(t *testing.T) { } func TestInvokeServStream(t *testing.T) { - ctx := context.Background() - - if resp, err := gc.Invoke(ctx, "User.UserResourceStatus", "GetEvent", `{}`, nil); err != nil { + if resp, err := gc.Invoke("User.UserResourceStatus", "GetEvent", `{}`, nil); err != nil { t.Error(err) } else if recv, err := resp.Recv(); err != nil { t.Error(err) @@ -81,9 +76,7 @@ func TestInvokeServStream(t *testing.T) { } } func TestInvokeBidiStream(t *testing.T) { - ctx := context.Background() - - if resp, err := gc.Invoke(ctx, "User.UserResourceStatus", "TestBidiStream", `"hello"`, nil); err != nil { + if resp, err := gc.Invoke("User.UserResourceStatus", "TestBidiStream", `"hello"`, nil); err != nil { t.Error(err) } else if send, err := resp.Send(); err != nil { t.Error(err)