[feat] Invoke 取消 context 参数

This commit is contained in:
what 2023-05-30 17:37:45 +08:00
parent af325a0ba6
commit 3d596598c6
2 changed files with 5 additions and 12 deletions

View File

@ -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()

View File

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